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 / Best way to create a dynamic third person camera?

Author
Message
Kafoolwho
11
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 12th Feb 2015 23:29
Good evening everyone. First of all, I want to thank everyone on the forums who has helped me in learning Darkbasic since last year, especially Mr. Valentine for all your great tips you have given me when running into a snag.

On to my newest problem:

I have to create a short third person shooter in the vein of Tomb Raider for an upcoming competition, and things are going pretty well, except for one small problem. I need a dynamic third person camera to follow the player, and Darkbasic's SET CAMERA TO FOLLOW command just isn't doing the job.
What I need is a camera which, when moving your character, follows the character at a specified distance, has camera smoothing, zoom levels and when looking up or down can look at where the character is looking.
Since I can't seem to get that last bit to work with SET CAMERA TO FOLLOW (and this is a very important prerequisite for the game, since the character has to be able to look down and up to be able to navigate the level), I was wondering what the best way is to create a dynamic third person camera for these purposes.

I am sure that the answer should be relatively simple, but I can't seem to be able to wrap my head around it. Any help and advice would be very much appreciated.

Thank you in advance.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Feb 2015 02:23
Create a transparent triangle, position it where you want the camera, set the camera position as the triangles... make the camera point in the direction of the polygon face/direction, use something like a while loop when the camera direction view is used to release it from the alternative view... But you could also use variables maybe... Quite a few ways to do this really... Oh just rotate the triangle to make the camera look in that direction...

And thanks back at you

Kafoolwho
11
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 13th Feb 2015 02:42 Edited at: 13th Feb 2015 02:43
And once again MrValentine comes to the rescue hehehe.
As I thought, a pretty simple and straightforward solution!
I have just added this into the engine, and mostly it does the job pretty well. I have the triangle pointing towards another invisible triangle in an area a ways in front of my character, which I raise and lower with the inverse of the mouse movement. The camera zoom I am handling by changing the first triangle's position on scrolling the mouse wheel (within specific bounds).

Thank you!

Now I just have to get some smoothing in here, since the camera feels a bit rigid...
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Feb 2015 03:12


Maybe some kind of linear interpolation sort of thing?

Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 13th Feb 2015 03:28 Edited at: 13th Feb 2015 04:06
Doing it the math way is basically:

Position = Target - (Rotation * Offset)

Then you'd lerp between the old position and new position for smoothing.

Position = Camera position
Target = The player models position
Rotation = The Direction the player is facing
Offset = The Zoom distance

If you were playing with Vector and Matrix math then this is really simple: EDIT: Amended code

Note: Require Ian's Plugin (if you don't have it get it anyway because it's a must for DBP)

You can actually do this without matrices and work out direction using a cheap method(or trig) using move object to work out direction then just multiply the offset by the direction.

"Get in the Van!" - Van B
Kafoolwho
11
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 13th Feb 2015 03:53
Thank you both.
I am saving both the linear interpolation theory and the code you provided, Sasuke, for reference in future projects.
You have both saved my bacon hehehe.
Much appreciated.

PS. Ian's Plugin was one of the first plugins I downloaded after purchasing DarkBasic Pro. I use it a lot.
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 13th Feb 2015 04:30 Edited at: 13th Feb 2015 04:34
Want to show an example of the cheap direction method I mentioned cause it's a bit of an odd one. Figured I'll just make a simple 3rd person camera with smoothing to show it off:



Just note, out of all the methods the matrix/vector one will be the fastest, second by trig math and then this method.

"Get in the Van!" - Van B
Kafoolwho
11
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 13th Feb 2015 04:39
Thanks, Sasuke. That is exactly what I needed. Works well!
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 13th Feb 2015 05:58 Edited at: 13th Feb 2015 05:59
SET CAMERA TO FOLLOW


windowsXp
Kafoolwho
11
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 13th Feb 2015 07:31 Edited at: 13th Feb 2015 07:31
pcRaider, thank you for your input. However, as I have stated in my original post, the SET CAMERA TO FOLLOW command's behavior just isn't sufficient for what I want to do, since the angle parameter does not provide you any way of looking up or down, and the control you have over the camera is rather limited.

The examples and theory provided by MrValentine and Sasuke are exactly what I was looking for.

Thank you very much for trying to lend a helping hand, though. I appreciate it!
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 13th Feb 2015 14:10
Kafoolwho, if you combine set camera to follow with point camera, you can achieve exactly what you want.

The only way to do great work is to love what you do -- Steve Jobs
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 16th Feb 2015 17:24
Kafoolwho is King's Valley (WIP) your project? saw images in the gallery just now... and put two and two together...

If it is not your project then I wish they would use user names or make it clear if it is there [is it?] on images...

Maybe people can add their Forum usernames to images?

Back on topic

Using set camera to follow with point camera might be a bit tricky, but not saying it cannot be done, just some tricky variable manipulation need to be worked out... if that is how TheComet perceives it... were you thinking to manipulate the camera using the variables within the camera angle commands? or directly apply Point Camera to the camera while it was being controlled by set camera to follow? not tried it yet...

Kafoolwho
11
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 17th Feb 2015 00:22
Nope. King's Valley is not my project. What I am working on is a very small sci-fi project about espionage for a competition.

And I totally agree with you about the gallery!
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 17th Feb 2015 02:57
As of Set Camera to Follow with Point Camera, since the camera needs to change it's height for when looking up and down you'd need to alter the height via mousemovey. You'd could clamp the height variable via camera angle or another method.

Ultimately it would be really unnatural movement since as you look down or up the camera would get further away from the scene because it's not orbiting it's focal point but rather shifting up and down to look at that focal point, the lower you look the further away the camera needs to be to reach the correct angle.

"Get in the Van!" - Van B
Kafoolwho
11
Years of Service
User Offline
Joined: 16th Oct 2013
Location: The Deep
Posted: 18th Feb 2015 10:44
Sasuke, that is the exact problem I had with SET CAMERA TO FOLLOW combined with POINT CAMERA. The examples and theory you provided really works wonders, though. I appreciate it!

Login to post a reply

Server time is: 2024-11-27 05:28:57
Your offset time is: 2024-11-27 05:28:57