Archived

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

Turning a ship towards a point in space...

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

Recommended Posts

What if there''s an object sitting in space with a position and rotation... now say that I want the ship to turn toward any point in 3d space, how would I do that? and please realize that the ship has a rotation vector (x,y,z). thanks

Share on other sites
that depends on what your rotation vector is. if it is a collection of three angles then delete it and forget the approach, it will throw away the order of applied rotations which is important to get the right result.

next: do you want to turn or just place it correctly? the latter would be easier but is usually not too useful. so you need two things: angle and axis. the axis should be the crossproduct between your current view direction and the vector from your position to the target point. the angle will be the inverse cos of the dotproduct (normalize them before). things will get more complicated if you dont just want to look at a point but also want a certain orientation.

another way would be transforming your current and target matrix to quaternions which are nicer to interpolate but introduce more overhead for converting back and forth.

Share on other sites
If I understand your need correctly - you should be able to use the same methodology as camera pointing. It is basic vector geometry to point something at something else (ie, get the angles between them).

There are loads of articles and tutorials on cameras and vectors. Check out the articles on this site or google it.

"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan

Share on other sites
I want it to turn in the direction of the vector, not point directly toward it...
could you maybe show me some code?
Thanks

Share on other sites
Make this ship have a state describing its rotational velocity, then just set that velocity to make it turn toward the point. On each frame draw/ time elapse rotate the ship according to the rotational velocity.

Pat

Share on other sites
could i see some code please?

Share on other sites
There is a thread here which deals with 3D enemy spaceship control. It discusses various techniques.

http://www.gamedev.net/community/forums/topic.asp?topic_id=180533

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• Forum Statistics

• Total Topics
633269
• Total Posts
3011152
• Who's Online (See full list)

There are no registered users currently online

×