Search Unity

Ballistic time of flight

Discussion in 'Physics' started by SparrowGS, Dec 9, 2018.

  1. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    I have the formula from wikipedia - https://en.wikipedia.org/wiki/Projectile_motion

    this is the code:
    Code (CSharp):
    1. public static float GetTimeOfFlight(float vel, float angle, float height){
    2.  
    3. //        return ((vel * Mathf.Sin (angle)) + Mathf.Sqrt (Mathf.Sin (angle) * Mathf.Sin (angle) + 2.0f * -Physics.gravity.y * height)) / -Physics.gravity.y;
    4.         return (2.0f * vel * Mathf.Sin (angle)) / -Physics.gravity.y;
    5.     }
    both of these line should return the same result, and they do, but the value i get is jumping between positive and negative, how could this be?
     
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    I'll tell you how you idiot, you're passing in degrees when it take radians.

    UGH!
     
    Joe-Censored likes this.