Search Unity

Limit velocity of Gravity (when i'm falling)

Discussion in 'Physics' started by Dinhov3, Oct 17, 2018.

  1. Dinhov3

    Dinhov3

    Joined:
    Sep 28, 2018
    Posts:
    3
    Hi guys i have a question. I was studying Unity and doing a plataform game. I add a rigidbody in my player and turn on the Gravity, but i saw one thing. When he still falling (because of gravity), he fall each time more fast.

    I want that he fall with a limit in that velocity. How could i do it in a simple way?
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Try configuring the Rigidbody's Drag property. The larger value, the smaller maximum velocity.
     
  3. centaurianmudpig

    centaurianmudpig

    Joined:
    Dec 16, 2011
    Posts:
    92
    You could clamp the value of the rigidbody.velocity to your desired max (+/-) velocity in FixedUpdate.
     
    unity_eJRTnMTI_g4mXA and jvggp like this.
  4. dontdiedevelop

    dontdiedevelop

    Joined:
    Sep 18, 2018
    Posts:
    68
    rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, maxVelocity); in FixedUpdate
     
    unity_eJRTnMTI_g4mXA likes this.
  5. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Just like in real life, with out any drag you dont have terminal velocity.

    You can just use the drag to have a limit on top speed, note that this effects accelartion too and doesnt decrease with height(like ksp does) and you cant just type "top speed = 100"

    Option two is to clamp the velocity vector to whatever like 2 have akready said
     
  6. Dinhov3

    Dinhov3

    Joined:
    Sep 28, 2018
    Posts:
    3
    Thank you guys, the Rigidbody.drag resolved this o/
     
  7. GuirieSanchez

    GuirieSanchez

    Joined:
    Oct 12, 2021
    Posts:
    452
    Sorry to necro this post, but I haven't seen much info about clamping the negative Y velocity.


    This works great, of course, but imagine I want to clamp the negative Y velocity to a really small amount, such as 0.5f. Then, of course, the character/obj will fall very slowly. Let's say that it takes him 10 seconds to reach the ground. My problem now is that, if I use the x input to move the character while falling, then the clamp will add the X velocity to the Y velocity. This results in a fall that takes the character more time that those 10 seconds when he was just falling (it may take 20 seconds, for instance).

    Is there any way in which you can set a maximum fall speed so that the character will fall at that very speed regardless of the X velocity?
     
  8. jbBbBbBbBb

    jbBbBbBbBb

    Joined:
    Mar 20, 2023
    Posts:
    1
    I'm also having the same issue.
     
  9. whoft

    whoft

    Joined:
    Jul 1, 2021
    Posts:
    29
    Use Mathf.Clamp instead.
    Code (CSharp):
    1. rigidbody.velocity = new Vector3(rigidbody.velocity.x, MathF.Clamp(rigidbody.velocity.y, minValue, maxValue), rigidbody.velocity.z)
    What this is doing is creating a new velocity vector with the other values unchanged and clamping ONLY the Y velocity.