Jump to content
  • Advertisement


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


Tracking a target

This topic is 6010 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

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

The Jackal

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!