August 2018
Beginner
334 pages
10h 19m
English
Thanks to our previous hard work, this recipe is a real piece of cake:
public static Vector3 GetFireDirection (Vector3 startPos, Vector3 endPos, float speed)
{
// body
}
Vector3 direction = Vector3.zero;
Vector3 delta = endPos - startPos;
float a = Vector3.Dot(Physics.gravity, Physics.gravity);
float b = -4 * (Vector3.Dot(Physics.gravity, delta) + speed * speed);
float c = 4 * Vector3.Dot(delta, delta);
if (4 * a * c > b * b)
return direction;
float time0 = Mathf.Sqrt((-b + Mathf.Sqrt(b * b - 4 * a * c)) / (2*a));
float time1 = Mathf.Sqrt((-b - Mathf.Sqrt(b * b - 4 * a * c)) / (2*a));
Read now
Unlock full access