Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Code for camera to follow player

Author
Message
Hilmi2k
21
Years of Service
User Offline
Joined: 29th Nov 2002
Location:
Posted: 9th Dec 2002 10:40
I have put some code in my game that I am writting in DB pro to make the camera follow the player. I too this code from the original DB tutorials, but modified it work in outerspace where there is no terrain...

it does not work as planned. I can see the object rotate infront of me but the camera does not follow the rotation. Please feel free to use any code you find useful here.

_player_motion:
if shiftkey()=1 then speedMulti# = 1.5 else SpeedMulti# = 1
if upkey()=1 then xrotate object 1,oAx# +5
if downkey()=1 then xrotate object 1,oAx# -5
if rightkey()=1 then yrotate object 1,oAy# +5
if leftkey()=1 then yrotate object 1,oAy# -5

rem this part of the code calculates the thrust in the current direction
if ObjForceNow# > 5 and spacekey()=0 then dec objForceNow#,10 else if objectForceNow#
Hilmi2k
21
Years of Service
User Offline
Joined: 29th Nov 2002
Location:
Posted: 9th Dec 2002 10:41
sorry, code got messed up... let me try again

_player_motion:
if shiftkey()=1 then speedMulti# = 1.5 else SpeedMulti# = 1
if upkey()=1 then xrotate object 1,oAx# +5
if downkey()=1 then xrotate object 1,oAx# -5
if rightkey()=1 then yrotate object 1,oAy# +5
if leftkey()=1 then yrotate object 1,oAy# -5

rem this part of the code calculates the thrust in the current direction
if ObjForceNow# > 5 and spacekey()=0 then dec objForceNow#,10 else if objectForceNow# <= 5 and spacekey()=0 then objectForceNow# = objectForceNow# - objectForceNow#
if spacekey()=1 then objectForceNow# = (objectForceNow# + (10 * SpeedMulti#))

rem this part of the code calculates the thrust in the actual movement achieved in the previous cycle
x1# = object position x(1)
y1# = object position y(1)
z1# = object position z(1)

oTAx# = objectTravelAngle(x1#,y1#,z1#,x2#,y2#,z2#,x)
oTAy# = objectTravelAngle(x1#,y1#,z1#,x2#,y2#,z2#,y)
oTAz# = objectTravelAngle(x1#,y1#,z1#,x2#,y2#,z2#,z)

oAx# = object angle x(1)
oAy# = object angle y(1)
oAz# = object angle z(1)

rotate object 1,oTAx#,oTAy#,oTAz#
displacement# = objdisp(1,oldforce#,objmass)
move object 1,displacement#
rotate object 1,oAx#,oAy#,oAz#
displacement# = objdisp(1,objectforcenow#,objmass)
move object 1,displacement#

x2# = object position x(1)
y2# = object position y(1)
z2# = object position z(1)

oldforce# = ObjForceCalc(pythag3d(x1#,y1#,z1#,x2#,y2#,z2#),objMass#)

rem this section positions the camera behind the player and slightly above
Camerax# = Newzvalue(x2#,oAx##-180,200)
Cameray# = Newzvalue(y2#,oAy##-180,200)
CameraZ# = Newzvalue(z2#,oAz##-180,200)

position camera Camerax#,Cameray#,CameraZ#
point camera x2#,y2#,z2#


return

Hilmi2k
21
Years of Service
User Offline
Joined: 29th Nov 2002
Location:
Posted: 11th Dec 2002 21:12
has anybody got any idea why this does not work? Its been a while longer than the normal quick response time... Or have I posted a challange too great for our ace programers

G Man X
21
Years of Service
User Offline
Joined: 11th Dec 2002
Location:
Posted: 13th Dec 2002 02:17
i may be talking through my interpreter but

Camerax# = Newzvalue(x2#,oAx#-180,200)
Cameray# = Newzvalue(y2#,oAy#-180,200)
CameraZ# = Newzvalue(z2#,oAz#-180,200)

has more appeal to me at a cursory glance...

Good The Boyz Have Done It Is!
Bulleyes
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 13th Dec 2002 06:02
Why not use the Set Camera To Follow() command?

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Hilmi2k
21
Years of Service
User Offline
Joined: 29th Nov 2002
Location:
Posted: 13th Dec 2002 08:19
THanx the both of you, I did not notice the double # in my code, must have been a typo. I will try it out and see what happens.

As for the command set camera to follow (), I'll go look it up in the help files.

Login to post a reply

Server time is: 2024-11-23 17:37:15
Your offset time is: 2024-11-23 17:37:15