Search Unity

how calculate reach top position from addforce and gravity ??

Discussion in 'Physics' started by Rnd--, Feb 15, 2015.

  1. Rnd--

    Rnd--

    Joined:
    Sep 27, 2012
    Posts:
    30
    Im making platformer games, and I want to change animation when my character jumps and reach top position

    Im jumping using script like this
    Code (CSharp):
    1. if(Input.GetButtonDown("Jump") && grounded)
    2.             rigidbody2D.AddForce(new Vector2(0f, 300));
    and Im using rigidbody2d, with gravityscale = 1 and mass = 1, physics2D setting for gravity (0, -9.81)
    anyone knows how to calculate when I reach top position ??
    Im thinking using rigidbody2D.velocity, cos I see the value when up until 5.8 and when fall the value when < 0
    but how I know the max value is 5.8 ??

    anyone can help ??
     
  2. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,022
    You can add a trigger variable in your animator controller that changes to a different animation when your y-velocity becomes negative, and reset it when you either become grounded again or grab onto something.

    I hope you're not confusing velocity with height when you talk about the value of 5.8.

    William