Archived

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

HanSoL0

Tracking a target

Recommended Posts

How do I use the local object matrices to determine the position of one object relative to another? I''m working on my game''s homing missile system and I want to be able to make the missile turn in the direction of its target. How do I put into code "If the target''s x position is to the right of the missile, turn right, if the target''s y position is above the missile, pitch up, etc..."? Ryan Buhr Trifinity Interactive, LLC.

Share this post


Link to post
Share on other sites
How are you keeping track of their positions, in the first place? When I get to that point of my game engine, I will probably do it by keeping a D3DXVECTOR3 in each object''s class. That way you could just subtract the x, y, and z for the rocket and its target to get the relative positons.

Proceeding on a brutal rampage is the obvious choice.

Share this post


Link to post
Share on other sites
You could make a lookat matrix using the missiles position as the "from" part and the targets position as the "at" part. This matrix will make the missile always look at its target.

Get the direction vector from this matrix to add into the missiles translation to move it. ( NewPos = OldPos + (Dir*ScalarVelocicty).

More complex solution would to create a quaternion from the missiles current orientation matrix, a quat from the lookat matrix. Then slerp between these and convert the resultant quaternion back to a matrix for the missiles new orientation.
This will give a "smooth" turning of the missile, while the first method just "snaps" to the target.

Point to note using the complex method is that you run the risk of making the missile orbit the target if it gets so close its turning circle is larger than the distance to the target.

Hope this is of some help.

[The views stated herein do not necessarily represent the view of the company Eurocom ]

Eurocom Entertainment Software
www.Eurocom.co.uk

The Jackal

Share this post


Link to post
Share on other sites