• Advertisement

Archived

This topic is now archived and is closed to further replies.

Ship simulation

This topic is 5360 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to create something like the Freelancer game, where the camera is located behind the ship you control. It allows you to move and rotate in any direction. I was able to fix the free look type of view for the camera but im having trouble in thinking of a way to generate the object in front of the camera. Currently I''ve used the camera target (gluLookat) to move the ship in front of it, but i can''t think of a way to rotate the ship so that it displays the correct orientation (which is where the camera looks directly at the back of the ship, top of the ship is also the top of the camera) any ideas on this one? I really need help

Share this post


Link to post
Share on other sites
Advertisement
Perhaps you can create a list of positions;
the last position the ship was at, at a given time, get stored in the list. Then the camera always interpolates to the next point in the list.

Just make sure that there´s a delay between creation of points, and til the camera moves.

just a thought. =) hope it helps!

"Game Maker For Life, probably never professional thou." =)

Share this post


Link to post
Share on other sites
Not too long ago I thought about this too. Basically there are two ways of doing a ''follow-cam'':

1. Store the position of the craft for a certain time (2 sec or so), and just position the camera at a past position looking at the next position. This will make sure that you see the movement of you ship. So if you turn left, the ship on the screen will be slightly left of the center. This should not be hard to implement, since you already have the points to feed into gluLookAt(..)

2. Get the current position of you ship, and then translate that position to the camera. This is a bit harder to make, but not much. The easiest way to do this, is first do gluLookAt(..) as if you were inside the cockpit, and then translate the entire world opposite the camera translation you wish. So if the camera should be 5 units behind the ship, translate EVERYTHING 5 units forward. If you do this, your ship will always be in the middle of the screen with the same orientation. However, this looks very static. If you''ve got this working, you can try applying a gradient or so to the translation/rotation so that the camera doesn''t follow the ship exactly. This should give the player some feeling of motion.

Good luck!

Share this post


Link to post
Share on other sites
the camera''s working already, im just having problems with the rotation of the ship. what i did was translate the ship right in front of the camera, so the only problem i have now is to make the ships orientation same with that of the camera ... (e.g. going left makes it turn to the left etc...)

Share this post


Link to post
Share on other sites
Let me get this straight: the ship is moving through the world, and the camera is always looking at the ship --> but where is the camera placed? This should be behind the ship, so multiply the heading of ship by an arbitrary constant and subtract this from the position of the ship. That should give you a position which in behind the ship at all times.

How do you get the position for the camera at the moment?

Share this post


Link to post
Share on other sites
quote:
Original post by shellshock
the camera''s working already, im just having problems with the rotation of the ship. what i did was translate the ship right in front of the camera, so the only problem i have now is to make the ships orientation same with that of the camera ... (e.g. going left makes it turn to the left etc...)


i dont know why, but somehow this sounds like "im flying the camera and draw the ship somewhere in front of it" when it should be "im flying the ship and place the camera behind it"

Share this post


Link to post
Share on other sites
From my code in DirectX

I created the camera behind the object, say -10.0 z behind, slightly above (y+5) - for sake of a figure.

Then I did a Camera->Lookat(co-ords of object).

When the object moved say x+1, I moved the camera x+1 - it was quite simple

Share this post


Link to post
Share on other sites
hm, in dx id have a matrix for each object anyway, so id just copy the objects matrix and adjust the position. though adding a spring like effect will make it feel a lot nicer.

Share this post


Link to post
Share on other sites
actually thats what i did .. hehehe ... i "thought" i got the camera working already so i just placed the object in front of it using translatef with the coordinates of the cameratarget .... whats worse is i discovered the camera wasn''t working right so im back to square 1 hehehe

Share this post


Link to post
Share on other sites

  • Advertisement