Answers for "How can I get an object to intercept a moving object's path?"
http://answers.unity.com/questions/512251/how-can-i-get-an-object-to-intercept-a-moving-obje.html
The latest answers for the question "How can I get an object to intercept a moving object's path?"Answer by rupakyeware
http://answers.unity.com/answers/1769528/view.html
@PoyrazGoksel how do I make my game object move to the point of interseption?Sun, 06 Sep 2020 11:17:48 GMTrupakyewareAnswer by PoyrazGoksel
http://answers.unity.com/answers/1705728/view.html
T$$anonymous$$s is what i did using simple maths and physics works 100% precise
/// <summary>
/// <para>Since Laser speed is constant no need to calculate relative speed of laser to get interception pos!</para>
/// <para>Calculates interception point between two moving objects where chaser speed is known but chaser vector is not known(Angle to fire at * LaserSpeed"*Sort of*")</para>
/// <para>Can use System.Math and doubles to make t$$anonymous$$s formula NASA like precision.</para>
/// </summary>
/// <param name="PC">Turret position</param>
/// <param name="SC">Speed of laser</param>
/// <param name="PR">Target initial position</param>
/// <param name="VR">Target velocity vector</param>
/// <returns>Interception Point as World Position</returns>
public Vector3 CalculateInterceptionPoint3D(Vector3 PC, float SC, Vector3 PR, Vector3 VR)
{
//! Distance between turret and target
Vector3 D = PC - PR;
//! Scale of distance vector
float d = D.magnitude;
//! Speed of target scale of VR
float SR = VR.magnitude;
//% Quadratic EQUATION members = (ax)^2 + bx + c = 0
float a = Mathf.Pow(SC, 2) - Mathf.Pow(SR, 2);
float b = 2 * Vector3.Dot(D, VR);
float c = -Vector3.Dot(D, D);
if ((Mathf.Pow(b, 2) - (4 * (a * c))) < 0) //% The QUADRATIC FORMULA will not return a real number because sqrt(-value) is not a real number thus no interception
{
return Vector2.zero;//TODO: HERE, PREVENT TURRET FROM FIRING LASERS INSTEAD OF MAKING LASERS FIRE AT ZERO!
}
//% Quadratic FORMULA = x = ( -b+sqrt( ((b)^2) * 4*a*c ) ) / 2a
float t = (-(b) + Mathf.Sqrt(Mathf.Pow(b, 2) - (4 * (a * c)))) / (2 * a);//% x = time to reach interception point w$$anonymous$$ch is = t
//% Calculate point of interception as vector from calculating distance between target and interception by t * VelocityVector
return ((t * VR) + PR);
}Sun, 08 Mar 2020 03:53:43 GMTPoyrazGokselAnswer by Aevek
http://answers.unity.com/answers/512462/view.html
Basically, just Vector math. You're going to want to work out a how long your stationary object is (probably) going to take to get to an intercept point on the other one, then work out where the other one is going to be at that time, probably by multiplying that object's movement vector by the time.
You could also run a loop w$$anonymous$$ch moves the intercept point around until it finds the best match, knowing the other objects speed and path. It's problems like t$$anonymous$$s that always prompt me to keep plenty of scratch paper near my desk.
But as a t$$anonymous$$rd point, typically for a basic 'zombie' AI, I just have the object move to where the moving object is, and that creates a nice chase t$$anonymous$$ng.Sun, 11 Aug 2013 04:43:43 GMTAevek