Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

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:
    51
    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:
    51
    What are you trying to do exactly ?
     
unityunity