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.

Dark GDK / Smooth Follow Camera...

Author
Message
Ninja_Je5us
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 19th Nov 2010 18:57
Hi,

I am building a 3D flying game using a jet fighter and would like to have a camera that follows the object. I have tried, unsuccessfully, to use the command dbSetCameraToFollow but it's not as smooth as I would like.

I have the jet moving perfectly, it is able to roll right and left, turn right and left (which involves a degree of roll as well as it looks more realistic), it can pitch up and down and moves in any direction using the space key.

Actually there's another question to do with the pitching of the plane. I want it to not be able pitch further than 90 degrees either way. Is that possible?

Any help is much appreciated.

Here's my code, please ignore anything commented out, i've tried on many occasions to make myself a smooth camera.

Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 20th Nov 2010 08:31
For the follow camera, an extremely simple way to move the camera would be something like

dbPositionCamera(dbObjectPositionX(1), dbObjectPositionY(1), dbObjectPositionZ(1));
dbSetCameraToObjectOrientation(1);
dbMoveCamera(-50);
dbMoveCameraUp(20);
dbPointCamera(dbObjectPositionX(1), dbObjectPositionY(1), dbObjectPositionZ(1));

There are easier ways that use triginometry but this is simpler to understand for a beginner.

To limit the roll you could do something like

if(dbObjectAngleZ(1)<90)
{
roll code
}
Ninja_Je5us
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 21st Nov 2010 21:34
Hi, thanks for your reply. I tried both of these things and unfortunately have managed to get neither to work. I started by putting everything as you have and it brought up an error because it wanted the "dbMoveCameraUp" function to take two arguments rather than one. Once I fixed this issue (probably wrongly) the camera ended up in front of the plane, whatever rotation I applied to the plane and didnt move with it.

I am working on the pitching issue but thats not a major problem for me at the moment.
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 22nd Nov 2010 02:48 Edited at: 22nd Nov 2010 15:30
Hey, I made some code that operates a smooth following, 3rd person style camera, and I made a smooth following camera for somebody else's flying game. I'm not completely sure that the second one works, though. The first one uses a little complicated trig, but I could explain it if you want.

First:
The 5's are the distance from the object(2) to the camera. If this line is put after a line that determines the rotation of the camera(Try This:
)[, you will be able to control the camera's movement and angle
while still having the camera remain in orbit about the object and always face the object. Of course, looking left will cause the camera to move right.



Second:
I think this will make your camera follow the object(3) 20 units back and always look forward, while it also moves the object(3) forward at a speed of one unit/refresh. Note, if your object flys backward you should use this:

Let me know if you have any questions.
Edit:
Here is some code that lets you control the angle and orientaion of the camera using an xbox 360 contoller.


uuhh... yah...
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 22nd Nov 2010 07:52 Edited at: 22nd Nov 2010 07:53
Ninja_Je5us
Quote: "
Hi, thanks for your reply. I tried both of these things and unfortunately have managed to get neither to work. I started by putting everything as you have and it brought up an error because it wanted the "dbMoveCameraUp" function to take two arguments rather than one. Once I fixed this issue (probably wrongly) the camera ended up in front of the plane, whatever rotation I applied to the plane and didnt move with it.

I am working on the pitching issue but thats not a major problem for me at the moment. "


That weird, usually you can just use one arg and it does it for the active camera. Try this:


Also, you have to call the code every loop, so put this code in the beginning of the while() section
Ninja_Je5us
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 22nd Nov 2010 23:11
Thanks for all of your replies.

Deadtom, I am trying your second method. It works in terms of positioning the camera and with a small tweak (namely putting a line saying dbMoveCamera(3) when the space bar is pressed and the model moves) it moves with the model, however if the plane pitches or turns it does not follow the model. I will post my code and you can have a look.

Any help is greatly appreciated

Ninja_Je5us
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 23rd Nov 2010 17:27
Sorry a bit of progress. I've managed to make the dbSetCameraToFollow command to follow the model, however I need to make the camera rotate when the plane does.

Im going to try pointing the camera and a couple of things.

Any ideas would be appreciated.
Ninja_Je5us
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 23rd Nov 2010 17:58
Hi,

Sorry to post again but I have managed to make it work to a standard that I am more than happy with.

Thank you very much for the help that you have all given me



And on to the next problem!
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 29th Nov 2010 00:51
Sorry I did not respond to your other posts. I did not have any internet for a few days. This was the final code that should toggle between gliding about the object and remaining behind it by pressing the shift key.

it is a full program but you should beable to figure out what parts should be transfered to another program.

uuhh... yah...

Login to post a reply

Server time is: 2024-06-30 10:17:22
Your offset time is: 2024-06-30 10:17:22