Hey,
I'm trying to make a moving Cube with Camera to Follow and a Camera wich you can rotate arround the object if the key q is pressed. I've got 2 problems with it:
1.) If I rotate the camera under the object the camera goes to its old position, but you don't look to the object, you look to the 'sky'.
2.) If I press the q key the camera doesn't start at the point it was, but at a diferent point. And If I let the programm position the object to the old camera position the camera moves fast away of the object.
Here is my code:
Sw=1024:Sh=768
set display mode Sw,Sh,32,1
sync on : sync rate 0
hide mouse
`Set Text
set text font "Verdana"
set text size 15
set text to bold
ink rgb(200,200,0),0
Make Matrix 1,500,500,20,20
Make Object Cube 1,1
Color Object 1,RGB(255,0,0)
Make Object Cube 2,1
Color Object 2, RGB(0,255,0)
Position Object 2,230,Get Ground Height(1,250,250)+1.0,250
Position Object 1,250,Get Ground Height(1,250,250)+1.0,250
speed# = 0.4
Do
`rotatse the object only incase of nonpressing of the key "v"
If KEYSTATE(16)=0
MMx = MouseMoveX()
Y# = WrapValue(Object Angle Y(1)+MMx): Yrotate Object 1,Y#
if upkey()=1 or KEYSTATE(17)=1
Move object 1, speed#
endif
if downkey()=1 or KEYSTATE(31)=1
move Object 1, -(speed#)
endif
if rightkey()=1 or KEYSTATE(32)=1
Move object right 1, speed#
endif
if leftkey()=1 or KEYSTATE(30)=1
Move object left 1, speed#
endif
if upkey()=1 AND downkey()=1 or KEYSTATE(17)=1 AND KEYSTATE(31)=1 or leftkey()=1 AND rightkey()=1 or KEYSTATE(30)=1 AND KEYSTATE(32)=1
Move object 1, 0
endif
endif
cpx1# = camera position x(0)
cpy1# = camera position y(0)
cpz1# = camera position z(0)
opx1# = object position x(1)
opy1# = object position y(1)
opz1# = object position z(1)
`Free Cammoving
if KEYSTATE(16)=1
position camera 0, opx1#, opy1#, opz1#
if mouseclick()=0
xrotate camera camera angle x()-mousemovey()*0.25
yrotate camera camera angle y()+mousemovex()*0.25
if camera angle x()>80 then xrotate camera 80
if camera angle x()<-60 then xrotate camera -60
endif
if mouseclick()>0 then CamDis#=CamDis#-mousemovey()*0.25
CamDis#=CamDis#+mousemovez()*0.25
if upkey()=1 or KEYSTATE(17)=1 then CamDis#=CamDis#+2.5
if downkey()=1 or KEYSTATE(31)=1 then CamDis#=CamDis#-2.5
if CamDis#>-20 then CamDis#=-20
if CamDis#<-300 then CamDis#=-300
move camera CamDis#
if camera position y()<-60 then position camera camera position x(),-60,camera position z()
mousemovex()=0
mousemovey()=0
endif
cpx# = camera position x(0)
cpy# = camera position y(0)
cpz# = camera position z(0)
opx# = object position x(1)
opy# = object position y(1)
opz# = object position z(1)
ObjHeight# = Get Ground Height(1,Opx#,Opz#)
Position Object 1,Opx#,ObjHeight#+1.0,Opz#
Camheight# = ObjHeight#+ReqCamHeight#
if KEYSTATE(16)=0
if cpx# > cpx1# then xrotate camera 0, cpx# - cpx1#
if cpx# < cpx1# then xrotate camera 0, cpx1# - cpx#
if cpy# > cpy1# then xrotate camera 0, cpy# - cpy1#
if cpy# < cpy1# then xrotate camera 0, cpy1# - cpy#
if cpz# > cpz1# then xrotate camera 0, cpz# - cpz1#
if cpz# < cpz1# then xrotate camera 0, cpz1# - cpz#
TrackAngle = 0:
ReqCamHeight# = 7.0
Camsmooth = 10
ColFlag = 0
Camdis# = 15
`Set Camera tp Follow
Set Camera To Follow Opx#,ObjHeight#,Opz#,WrapValue(Object Angle Y(1)+TrackAngle),Camdis#,Camheight#,Camsmooth,ColFlag
endif
`Text
center text sw/2,50,"FPS "+str$(screen fps())
Sync
Loop
Sorry for my bad english :S
It's not a bug it's a feature