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 / noobcore Camera follow problems

Author
Message
sparticaldidit
13
Years of Service
User Offline
Joined: 2nd Feb 2011
Location:
Posted: 2nd Feb 2011 07:54
Hello friends just started using darkbasicpro a couple of days ago
and just having some trouble with the camera follow command.

I have it working just not as good as I would like.

when I turn for a certain amount of time the camera stops rotating
while the cube keeps rotating,at first i thought this was to do with
the camera hitting the bsp but when i take out the bsp camera collision command it still happens so im not sure why this happens.

any help on how to improve this code would be helpful thanks


this is my code:


rem Set camera
set camera range 0.1,5000
position camera 0,50,0
rotate camera 0,45,0

rem set variables
Camdist# = 80
TrackAngle = 0
CamHeight# = 100
Camsmooth = 15
ColFlag = 0

Make Matrix 1,500,500,20,20

REM MAKE PLAYER
MAKE OBJECT CUBE 1,30
POSITION OBJECT 1,0,50,10


REM BSP SET UP
LOAD BSP "MAP/level.dat","my first bsp.bsp"
set bsp camera collision 1,0,0.75,0
set bsp collision threshhold 1,0.001
set bsp object collision 2,1,8,0


rem Main loop
do



rem control cube
if upkey() then move object 1,2
if downkey() then move object 1,-2
if leftkey() then TURN OBJECT LEFT 1,1
if rightkey()then TURN OBJECT right 1,1
if keystate(30) then move object left 1,2
if keystate(31) then move object right 1,2



REM CAMERA FOLLOW
ObjX# = Object Position X(1)
ObjZ# = Object Position Z(1)
ObjHeight# = Get Ground Height(1,ObjX#,ObjZ#)

Set Camera To Follow ObjX#,ObjHeight#,ObjZ#,WrapValue(Object Angle Y(1)+TrackAngle),Camdist#,Camheight#,Camsmooth,ColFlag




rem Update screen
sync

rem End loop
loop

spartical did do it
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Feb 2011 13:56
When you add code to a forum post put it between these [.code]your code here[/.code] but without the dots. It's much neater.

Here is one solution (just edited how you were getting the player angle):


Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 5th Feb 2011 05:03
I've found that using SET CAMERA TO FOLLOW in combination with TURN OBJECT LEFT/RIGHT can cause problems if you're using OBJECT ANGLE Y() to get the angle. Try using YROTATE OBJECT instead. In this case you would simply rotate an object to its current angle plus however much you want it to rotate. So if you had this:
Turn Object Right 1,2

it would become this:
Yrotate Object 1, Object Angle Y(1) + 2

or this:
Yrotate Object 1, Wrapvalue( Object Angle Y(1) + 2 )

To make the object turn left you would just subtract 2 from the angle instead, like this:
Yrotate Object 1, Object Angle Y(1) - 2

Hope this helps!


Guns, cinematics, stealth, items and more!

Login to post a reply

Server time is: 2024-11-23 03:49:15
Your offset time is: 2024-11-23 03:49:15