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.

Author
Message
OmegaGT96
15
Years of Service
User Offline
Joined: 15th Mar 2011
Location: Italy
Posted: 15th Mar 2011 15:27
I'm creating a third person shooter, but I have a problem: I can't rotate the camera around the player.
Thanks in advance
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Mar 2011 17:07
What I would tend to do, is tilt the camera forward a little, and rotate it's Y axis to suit the player. So maybe something like this: (assuming object 100 is your player)

Rotate camera 15,object angle y(100),0

Then position that at the player object, maybe adding some to the Y position...

Position camera object position x(100),object position y(100)+10.0,object position z(100)

Now that's more like a depressed FPS camera, but if you move the camera backwards it should give a reasonable 3rd person camera...

Move camera -200

You will have to adjust those scales. But remember curveangle, and how that could smoothen things out - for example, use a variable to track the cameras X and Y angles, and set them to the player angle. This gives smoother results, and will let you see the character when it turns, because the curvevalue will move the camera in X steps.

So... before your main loop, set those to default values - not really that important in DBPro but I find it's good for helping me remember variable names.

camAX#=0.0 : camAY#=0.0
camTAX#=0.0 : camTAY#=0.0

That's a target X and Y angle, and the current X and Y angle, to allow smooth rotation.

Now inside your main loop, you need to adjust the current angles to suit the target angles once you've calculated the targets, so camAX# moving towards camTAX#...

camTAX#=15.0
camTAY#=object angle y(100)

camAX#=curveangle(camTAX#,camAX#,10.0)
camAY#=curveangle(camTAY#,camAY#,10.0)

Rotate camera camAX#,camAY#,0.0
Position camera object position x(100),object position y(100)+10.0,object position z(100)
Move camera -200

There's lots you can do with that to make it better, like adjustable zoom, have it wind up and zoom out to show a top down map view, or even project an intersection line from the player to the new camera position, and set the camera to the collision point if there is one.

Health, Ammo, and bacon and eggs!
OmegaGT96
15
Years of Service
User Offline
Joined: 15th Mar 2011
Location: Italy
Posted: 15th Mar 2011 23:39
Problem. I have attached the game.
Here's the source code:
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 16th Mar 2011 00:56
Ahh, seems that turning an object left or right can mess the returned angle up. Works now, added some globals, and right click to rotate the camera.



Health, Ammo, and bacon and eggs!
OmegaGT96
15
Years of Service
User Offline
Joined: 15th Mar 2011
Location: Italy
Posted: 16th Mar 2011 15:06
OOOH, thanks
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 16th Mar 2011 21:14
@Van B - nice FPS camera/curveangle tutorial, Thanks!
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 16th Mar 2011 23:56
No problem, curveangle and curvevalue are really handy for smoothing things out huh!

Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2026-07-17 13:58:59
Your offset time is: 2026-07-17 13:58:59