Search Unity

Speed up movement using Rigidbody physics?

Discussion in 'Physics' started by thedevilsjester, May 26, 2018.

  1. thedevilsjester

    thedevilsjester

    Joined:
    May 21, 2018
    Posts:
    25
    Hello,

    Is there a way to make objects move faster using a Rigidbody, without changing their direction or angle?

    What I mean is that, say I give a Rigidbody a velocity of Vector(0, 8, 10), thats a very specific arc that the object will travel through. I want to keep that same travel arc, but I want the object to arrive at the destination much faster.
     
  2. ThaBullfrog

    ThaBullfrog

    Joined:
    Mar 14, 2013
    Posts:
    49
    The issue here is gravity. In real life it is impossible to toss a ball in the exact same arc at two different speeds because gravity always accelerates at the same rate. The faster throw will go farther because gravity doesn't also speed up.

    If you really want this effect you could tweak gravity on the object to keep on the same path. Square the multiplier that you use on the velocity and use it on the gravity. So if you double the velocity, quadruple the gravity.

    How can you change the gravity on a single object? Well, you can't, but you can add your own downward acceleration to simulate this effect. We subtract 1 from the multiplier to account for the regular gravity.

    Code (CSharp):
    1.  
    2. void FixedUpdate()
    3. {
    4.     rigidbody.AddForce(Physics.gravity * (gravityMultiplier - 1f), ForceMode.Acceleration);
    5. }
    6.  
     
    benjicsoft and SparrowGS like this.
  3. thedevilsjester

    thedevilsjester

    Joined:
    May 21, 2018
    Posts:
    25
    Thank you for the reply, I switched over to using a mechanism that does not require a Rigidbody, but I will store this away for later.