Search Unity

Jump with the last speed detected (PROBLEM)

Discussion in '2D' started by PainStone, Jun 14, 2019.

  1. PainStone

    PainStone

    Joined:
    Apr 20, 2019
    Posts:
    4
    Hello! I am a new programmer and I need to know how to make my character jump with the last detected speed before jumping and keep that speed in the air.
     
  2. hemang2413

    hemang2413

    Joined:
    Jun 14, 2019
    Posts:
    1
    Are you using rigid body physics or transform to move your player?
     
  3. coidevoid

    coidevoid

    Joined:
    Oct 26, 2017
    Posts:
    27
    If you are using the RigidBody2D component then just add a varialbe that store this value before you jump.


    Code (CSharp):
    1. Vector2 jumpForce
    2.  
    3. void Jump()
    4. {
    5. jumpForce = body.velocity;
    6. //Jump
    7. }
     
  4. PainStone

    PainStone

    Joined:
    Apr 20, 2019
    Posts:
    4
    Yeah im using rb2d

    i got this

    void Jump()
    {
    rb2d.AddForce(new Vector2(0, jumpForce));
    }
     
  5. coidevoid

    coidevoid

    Joined:
    Oct 26, 2017
    Posts:
    27
    What are you trying to do exactly ?