Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. 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
  3. 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

Velocity increases faster after large force is applied.

Discussion in '2D' started by Deci260, Sep 20, 2019.

  1. Deci260


    Sep 15, 2019
    Hello, I'm working on a small project where a ball can either jump or roll. Basically when the user holds the left mouse button I call the
    function with a really small value on the x to slowly increase the velocity until it gets to the max (10). Here's a small part of the
    function where I decide how much force I'm going to add:

    Code (CSharp):
    2. if(rb.position.x < point2.x)
    3. {
    4.       moveVelocity = new Vector2(0.1f, 0);
    5. }
    7. else
    8. {
    9.       moveVelocity = new Vector2(-0.1f, 0);
    10. }
    And then the

    Code (CSharp):
    1. if(!jumping)
    2.         {
    3.             rb.AddForce(moveVelocity, ForceMode2D.Impulse);
    4.         }
    By using the code above the ball gets to the mavelocity in around 5 seconds.
    As I said, the ball can also jump and it does that when the user drags the mouse while holding the left button. The force on the jump is calculated by the distance covered by the mouse, here's part of the code that does that:

    Code (CSharp):
    1. var forcey =  (mouseClickPosition.y - Input.mousePosition.y) / 25;
    2. var forcex =  (mouseClickPosition.x - Input.mousePosition.x) / 25;
    4. jumpVelocity = new Vector2(forcex, forcey);
    Like before, the
    vector will be used as the arg in a
    call in the

    To slowly decrease the velocity after a jump or a roll I'm using the same code as when calculating the force for the rolls but with swapped values and with a stop when the velocity gets to 0.

    The code above works fine until the user actually jumps. After the landing both the decrease in velocity and the increase to 10 when rolling are instantaneous. I have no Idea why this is happening. I would really appreciate if you could point me in the right direction.