Make movement more slippery

Hi guys,

How can i make this objects movement a bit more “Slippery” so that it doesnt just stop immediately when a controller is let go? i have 0 on both my drags.

public class GunStarController : MonoBehaviour
{
    public float speed;
    public float tiltLeftRight;
    public float tiltForwardBack;
    public Boundary boundary;
    public Rigidbody rigidbody;

    private void FixedUpdate()
    {
        float moveHorizontal = SimpleInput.GetAxis("Horizontal");
        float moveVertical = SimpleInput.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        rigidbody.velocity = movement * speed;
}

If you want to do it manually, just lerp from the current velocity to the new velocity. You can still decide how quickly you’re lerping in various circumstances.
IDK what the SimpleInput is, but if it is a wrapper for the old Input class and it’s not the new one with reading in the FixedUpdate cycle, you should move out the input part into an Update function.

Exactly what Lurk says above… and honestly I would just do it with that same old currentQuantity and desiredQuantity approach, but for velocities.

  • only set desiredVelocity from inputs
  • Have currentVelocity always go towards desiredVelocity
  • Always use the currentVelocity to move

You know the ilnk:

Smoothing movement between any two particular values:

https://discussions.unity.com/t/812925/5

You have currentQuantity and desiredQuantity.

  • only set desiredQuantity
  • the code always moves currentQuantity towards desiredQuantity
  • read currentQuantity for the smoothed value

Works for floats, Vectors, Colors, Quaternions, anything continuous or lerp-able.

The code: https://gist.github.com/kurtdekker/fb3c33ec6911a1d9bfcb23e9f62adac4

Cool , will give this a go. I notice when setting up movement for objects that sometimes it works naturally like this. Is it just the differences in setting up movement? transforms vs rigidbody’s?

If you use addforce and drag or whatnot, you can get some naturally slippery movement because in that case you are controlling the rigidbody indirectly using the physics engine. On the other hand, when you set the velocity explicitly like you’re doing now, you’re basically over-riding the physics engine and taking direct control for yourself, so it’s not slippery unless you make it slippery.

Neither approach is necessarily better or worse, it just depends on what you need.

2 Likes

Got it working perfectly thank you!