Search Unity

Trying to Calculate a Jump Arc (Kinematic Equation Needed?)

Discussion in 'Physics' started by ErnestoBananez, Jan 26, 2016.

  1. ErnestoBananez

    ErnestoBananez

    Joined:
    Sep 23, 2014
    Posts:
    16
    Hi all. I'm working on a 2D platformer based on this guy's (amazing) tutorial series. I plan to study, extend, and shift his controller around until I have something that works for me. Important note- it's made without Unity rigidbodies. Everything is coded from scratch, and the only Unity physics-related system it relies on is raycasting (for collision checking).

    Anyway, there's something I've been trying to understand for a while, and that's how to calculate a jump that would get a character from a point A to a point B, but with a realistic arc instead of a straight interpolation. Here's a drawing:

    Jump Arc.jpg

    That's what I had in mind. One more note about it: this jump will be independent of player input as it's happening. Once the jump is initiated, it continues until it's finished, and at that point control is returned to the player, so there's no worrying about how this will interact with character control. It's a different 'type' of jump than a standard platformer jump, so it behaves differently. It's like an auto jump that the player can use in certain scenarios.

    I'm hoping there's some sort of physics equation out there that could help me calculate the arc, so I thought I'd come here since my knowledge of physics is okay at best. Can anyone help me? I'd really appreciate it :) Even pointing me to an article or two would help.
     
  2. Harpoon

    Harpoon

    Joined:
    Aug 26, 2014
    Posts:
    20
    Do you want to know exactly when your character will land or just calculate the jump in real time.
    If just the second, the whole process should be simple and will require adding few vectors every frame during jump

    Code (CSharp):
    1. if (pressX)
    2. {
    3.     fall = 0;
    4.     speed = yourcurrentspeed;
    5.     jump = true;
    6.     drag = 0;
    7. }
    8.  
    9. if (jump)
    10. {
    11.     drag = -speed * dragmultiplier * Time.DeltaTime;
    12.     fall -= -9,8 * Time.DeltaTime;
    13.     transform.position += new Vector2(speed*Time.DeltaTime, jumpSpeed * Time.DeltaTime) + new Vector2(drag, fall);
    14. }

    Now, if you put these calculations in a loop and replace transform.position with some temporary Vector2 you will get the jump trajectory.
    If you want to calculate how much speed and force you need to complete the jump you can use these equations: http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html#tra4
     
    Hozgen90 likes this.