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.

DarkBASIC Professional Discussion / Centering camera behind player

Author
Message
CodeSlinger
23
Years of Service
User Offline
Joined: 3rd May 2003
Location:
Posted: 7th Jul 2003 06:03
Hey all,
I'm sure is relatively a simple task but I have worked with for a couple hours now and haven't had much success. My game is FPS style but I am allowing two different views. One is a true first person view (i.e. cam only), the other is a behind player view (camera follows a bit above and behind the player). What I am having trouble with is the behind player view. I'm trying to keep the camera behind the player no matter what direction he is facing but instead my object (the character) turns and camera does not. I've tried rotating the camera with the player (using yrotate object + yrotate camera together) but that does not appear to work). I was wondering if anyone else has run into this problem before and could point me in the right direction for solution.
Shining Moonblade
23
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 7th Jul 2003 06:23
Ah. A 3rd person camera. Okay, here goes:

Create 3 camera veriables

camx# as float
camy# as float
camz# as float

camy# should be the object height (or whatever you like) + height of the object in the level.

camx# should be calculated like this:
camx# = newxvalue(object position x(Player Object), wrapvalue(object angle y(Player Object) + 180), Number of units that you want the camera to be from your object)

camz# is like this:
camz# = newzvalue(object position z(Player Object), wrapvalue(object angle y(Player Object) + 180), Num of Units)

So assuming your player object is #1 and you want the camera 80 units behind your player it looks like this:
camy# = object height(1) + object position y(1)
camx# = newxvalue(object position x(1), wrapvalue(object angle y(1) + 180), 80)
camz# = newzvalue(object position z(1), wrapvalue(object angle y(1) + 180), 80)

Then make sure to position the camera:
position camera camx#, camy#, camz#

Pretty simple. The basic idea is to take the player objects position in space, and calculate where the camera should be relative to the player object's orientation. Thus the wrapvalue(object angle y(1) + 180) If the 180 becomes 90 or 270, the camera will be to the left or right of the object. Play around with the values and see what you get.

And one more thing: Make sure that the distance the camera is from the player can be flexible so that if the camera is smacking a static object it can move.

Watashi no namae wa Zeroshin desu! Hashitekudasai!
CodeSlinger
23
Years of Service
User Offline
Joined: 3rd May 2003
Location:
Posted: 8th Jul 2003 04:21
Hey thanks for help.
I tried your code with the camera and it still is not doing I want it to do. My code is posted here along with comments. The problem I'm having is the camera not centering behind the player when he turns left or right. As you can see I was originally using the Set Camera to Follow command.
Any other suggestions?

Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 8th Jul 2003 07:50 Edited at: 8th Jul 2003 07:55
easiest way is this



i'm sure you an figure out from there what to do

[edit-]
i forgot the rotation :">

Login to post a reply

Server time is: 2026-07-17 13:56:46
Your offset time is: 2026-07-17 13:56:46