I am giving a go at a game I wanted to make, reliant on physics and strategy to complete objectives. Right now I am starting out with the basics, a free-moving camera that rotates around the player model. However, I have hit a wall in development.
The camera does not follow the player right now, and the player, I don't think, rotates. Or at least the model does not. I think I have some misplaced variables, but if anyone could lend me a hand on how to make it so the camera will follow the player, but still be able to rotate freely around it, that would be appreciated. Also, how would I rotate the player model? I only have one angle value, so I do not have an x y and z separate. Here is the code, if anyone could help me clean it up...
sync on
hide mouse
`*** Set display settings ***
SCREENX = 1024
SCREENY = 768
set display mode SCREENX,SCREENY,32
`*** Create objects to view ***
load object "models/char.x",1
position object 1, 0, 0, 0
`*** Set object collision for camera ***
automatic camera collision 0, .25, 1
`*** position camera variables ***
x# = 0
y# = 0
z# = -400
a# = 0
`*** point and position camera variables ***
pcx# = 0
pcy# = 0
pcz# = 0
position camera x#, y#, z#
point camera 0, 0, 0, 0
bearing# = 20
azimuth# = 20
distance# = 30
`*** Setup last camera variables ***
LASTMOUSEX = MOUSEX()
LASTMOUSEY = MOUSEY()
LASTMOUSEZ = MOUSEZ()
do
`*** show the mouse ***
`*** Reset model to center if SPACE pressed ***
IF SCANCODE() = 57
pcx = 0
pcy = 0
pcz = 0
point camera 0, 0, 0, 0
ENDIF
`*** Read current mouse coordinates ***
CURRENTMOUSEX = MOUSEX()
CURRENTMOUSEY = MOUSEY()
CURRENTMOUSEZ = MOUSEZ()
`******************************************************
`*** Wrap mouse around screen if right mouse button clicked ***
IF MOUSEX() = 0
Position mouse SCREENX - 2, MOUSEY()
ENDIF
IF MOUSEX() = SCREENX - 1
position mouse 1, MOUSEY()
ENDIF
IF MOUSEY() = 0
Position mouse MOUSEX(), SCREENY - 2
ENDIF
IF MOUSEY() = SCREENY - 1
position mouse MOUSEX(), 1
ENDIF
`*** Move view of object if holding down shift and right mouse ***
IF SCANCODE() = 42
IF CURRENTMOUSEX > LASTMOUSEX
pcx = pcx + 1
ENDIF
IF CURRENTMOUSEX < LASTMOUSEX
pcx = pcx - 1
ENDIF
IF CURRENTMOUSEY > LASTMOUSEY
pcy = pcy + 1
ENDIF
IF CURRENTMOUSEY < LASTMOUSEY
pcy = pcy - 1
ENDIF
ENDIF
`*** Right mouse button clicked and shift not down - rotate camera ***
if CURRENTMOUSEX < LASTMOUSEX AND SCANCODE() <> 42
bearing# = wrapvalue(bearing# + 3)
endif
if CURRENTMOUSEX > LASTMOUSEX AND SCANCODE() <> 42
bearing# = wrapvalue(bearing# - 3)
endif
if CURRENTMOUSEY < LASTMOUSEY AND SCANCODE() <> 42 and azimuth# < 179
azimuth# = wrapvalue(azimuth# + 3)
endif
if CURRENTMOUSEY > LASTMOUSEY AND SCANCODE() <> 42 AND azimuth# > 2
azimuth# = wrapvalue(azimuth# - 3)
endif
`*** Zoom with mouse wheel ***
IF CURRENTMOUSEZ < LASTMOUSEZ
distance# = distance# + 1
ENDIF
IF CURRENTMOUSEZ > LASTMOUSEZ
distance# = distance# - 1
ENDIF
`*** Zoom by holdign both mouse buttons with cursor wrap ***
IF MOUSECLICK() = 3
HIDE MOUSE
`*** wrap mouse during zoom ***
IF MOUSEX() = 0
Position mouse SCREENX - 2, MOUSEY()
ENDIF
IF MOUSEX() = SCREENX - 1
position mouse 1, MOUSEY()
ENDIF
IF MOUSEY() = 0
Position mouse MOUSEX(), SCREENY - 2
ENDIF
IF MOUSEY() = SCREENY - 1
position mouse MOUSEX(), 1
ENDIF
`*** Perform zoom ***
IF CURRENTMOUSEY < LASTMOUSEY
distance# = distance# - .2
ENDIF
IF CURRENTMOUSEY > LASTMOUSEY
distance# = distance# + .2
ENDIF
ENDIF
if scancode()=17
pcx#=newxvalue(pcx#,a#,0.1)
pcz#=newzvalue(pcz#,a#,0.1)
endif
if scancode()=30
a#=a#-2.0
endif
if scancode()=32
a#=a#+2.0
endif
`*** Set current mouse position as last mouse position ***
LASTMOUSEX = MOUSEX()
LASTMOUSEY = MOUSEY()
LASTMOUSEZ = MOUSEZ()
`*** Calculate camera position ***
x# = distance# * sin(azimuth#) * cos(bearing#)
z# = distance# * sin(azimuth#) * sin(bearing#)
y# = distance# * cos(azimuth#)
`*** Position and point camera ***
position camera x# + pcx#, y# + pcy#, z#
point camera 0, pcx#, pcy#, pcz#
`*** Display various stats ***
set cursor 0, 0
print "x: ";x#;" y: ";y#;" z: ";z#
print "pcx: ";pcx;" pcy: ";pcy;" pcz: ";pcz
print "bearing: ";bearing#
print "azimuth: ";azimuth#
print "distance: ";distance#
print "scancode: ";SCANCODE()
print "mosue x: ";mousex()
print "mouse y: ";mousey()
print "mouse z: ";mousez()
print "fps: ";screen fps()
sync
loop