Need Evaluation!

Need Evaluation!

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Pendrokar
Posts: 658
Joined: 30 May 2007, 10:45

Need Evaluation!

Post 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!
User avatar
Peet
Malcontent
Posts: 4384
Joined: 27 Feb 2006, 22:04

Re: Need Evaluation!

Post by Peet »

Check spring's code, it does exactly the same thing when it aims :)
I'll have a look when I get home.
Auswaschbar
Spring Developer
Posts: 1254
Joined: 24 Jun 2007, 08:34

Re: Need Evaluation!

Post 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
User avatar
ILMTitan
Spring Developer
Posts: 410
Joined: 13 Nov 2004, 08:35

Re: Need Evaluation!

Post 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.
Attachments
15161_wheretoshoot_122_476lo.jpg
(18.54 KiB) Downloaded 185 times
Post Reply

Return to “Lua Scripts”