Tracking Algorithm?
Im trying to make my object track another, so far my code gets all the relavent info but im not sure what to do with it.
I cant make the simple one, if x is less than x2 go left... Because my game objects dont move left or right, they rotate.
So..
object ax
||| pos(10,10)
object bx
|||
i want object bx to track ax, but the problem is, because i can only rotate object bx, i need someway, to work out which way to rotate it, to make it face object ax, then i can move towards it.
I hope you can help.
Thanks alot all.
Cya
First, a comment: This sort of problem has been asked and answered many times in the Maths & Physics forum. You might first want to check the archives of that forum in the future, if you have a question of this type (that goes for everyone else as well). For now though, here is the answer you seek...
There are two parts to this problem:
1) Determine the smallest angle between the two objects; and,
2) Determine the direction to rotate through that angle (positive or negative sense).
First, define two vectors, A andB , being the vectors from the origin to the objects a and b respectively. Then,
Part 1)
Part 2)
The cross product of two vectors is orthogonal to the plane that they define and is a signed operation... meaning that if you reverse the two vectors, you get the negative of the value.
The cross product operation follows a right hand rule so if you want to work out the direction for a rotation from b to a, take the cross product,
If it is positive, then rotate theta radians in the positive direction (counterclockwise), else if it is negative, rotate theta radians in the negative (clockwise) direction.
Cheers,
Timkin
[edited by - Timkin on April 27, 2002 9:56:12 PM]
There are two parts to this problem:
1) Determine the smallest angle between the two objects; and,
2) Determine the direction to rotate through that angle (positive or negative sense).
First, define two vectors, A andB , being the vectors from the origin to the objects a and b respectively. Then,
Part 1)
A . B theta = cos-1(------) |A| |B|
Part 2)
The cross product of two vectors is orthogonal to the plane that they define and is a signed operation... meaning that if you reverse the two vectors, you get the negative of the value.
The cross product operation follows a right hand rule so if you want to work out the direction for a rotation from b to a, take the cross product,
B x A
If it is positive, then rotate theta radians in the positive direction (counterclockwise), else if it is negative, rotate theta radians in the negative (clockwise) direction.
Cheers,
Timkin
[edited by - Timkin on April 27, 2002 9:56:12 PM]
also, if you want to extend your tracking algo. you can implement an intercept personality to your tracking unit. basically you track a point ahead of the target based on the current movement. you would use the last few positions and extrapolate the next position. the difficulty though lies in the correct extrapolation. a simple scheme uses the current speed in a linear fashion and tries to predict the best route based on that information. this may sound like a ramble and be somewhat confusing, but it is merely to get your creative juices flowing once you get the standard follow a target routine working.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement