Page 1 of 1

Need Evaluation!

Posted: 08 Jan 2008, 19:05
by Pendrokar
I have a problem with object collision prediction!
Image
The red dot with speed is the immobile objects bullet, which it shoots!
So the primary question is "At this moment where does the immobile unit shoot so that the bullet would collide with the moving object?"(Or otherwise at what direction the immobile unit needs to shoot for the bullet to collide?) As I understand there is no formula for this! Feel free to modify the image.
Edit: Timing doesn't matter!

Re: Need Evaluation!

Posted: 08 Jan 2008, 19:12
by Peet
Check spring's code, it does exactly the same thing when it aims :)
I'll have a look when I get home.

Re: Need Evaluation!

Posted: 08 Jan 2008, 20:02
by Auswaschbar
If the bullet is much faster than the object, it might be sufficient to shoot at:
r_1 + (distance / v_b) * v_1
where
r_1 is the position of the moving object while shooting
v_b is the bullet speed
and v_1 is the speed vector of the moving object

Re: Need Evaluation!

Posted: 08 Jan 2008, 20:49
by ILMTitan
Image
V1*t + S2*d2*t = R : where d2 is the unknown unit vector and t is the unknown time.
Breaking into x and z parts:
t= Rx/(V1x + S2*sin(theta))
V1z + S2*cos(theta) = Rz/t = (Rz*V1x + Rz*S2*sin(theta))/Rx
(V1z*Rx - V1x*Rz)/S2 = Rz*sin(theta) - Rx*cos(theta)
(V1z*Rx - V1x*Rz)/(S2*Magnitue(R)) = sin(theta)*cos(alpha) - sin(alpha)*cos(theta) = sin(theta - alpha)

theta = arcsin((V1z*Rx - V1x*Rz) / (S2*Magnitude(R)) + alpha

from there it is easy to find d2, the direction to aim in.

This gets more complicated if ballistics are factored in.