Ok, I haven't programmed for a really long time, but today I decided to start to get back into it. I decided I wanted to make a basic 3rd person shooter, but I've seemed to hit a problem. I want it so as I move the mouse and rotate the camera, the player object rotates with it so it never leaves the screen, but also stays a bit of a distance infront of the camera so you can still see it. However, I've tried a few different things, and I just can't seem to get it right.
Here's my basic code without my failed implentation of the object rotation:
sync on:sync rate 30
hide mouse:autocam off
`make object cube
make object cube 1,5
position object 1,0,0,0
`make player cube
make object cube 2,2
position object 2,0,0,-15
position camera 0,2,-20
`make camera rotation
make object box 3,1,1,4
do
`player variables
x# = object position X(2)
y# = object position Y(2)
z# = object position Z(2)
`camera variables
cx#= camera position X()
cy#= camera position y()
cz#= camera position z()
`camera movement
rotate camera camera angle x(0)+(mousemovey()/4.0),camera angle y(0)+(mousemovex()/4.0),0
if wrapvalue(camera angle x(0))>40 and wrapvalue(camera angle x(0))<180 then xrotate camera 0,40
if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280
`player movement
if upkey()=1
move object 2,.3
endif
if downkey()=1
move object 2,-.3
endif
if rightkey()=1
move object right 2,.3
endif
if leftkey()=1
move object left 2,.3
endif
position camera x#, y# + 3, z#-4
yrotate object 2,camera angle y()
sync
text 0,0, "player x= " + str$(x#)
text 0,15, "player y= " + str$(y#)
text 0,30, "player z= " + str$(z#)
text 0,45, "camera postition = " + str$(cx#) + " " + str$(cy#) + " " + str$(cz#)
loop
This is where my signature would be If I had one.