L
L
LittleBob2022-01-14 20:12:10
Unity
LittleBob, 2022-01-14 20:12:10

How to make inertial motion in Unity2D?

In Rigidbody2D gravity is set to 0, mass is 1. When I use velocity, the object just moves, when I use AddForce the object for some reason acquires infinite acceleration and movement. It is necessary for me that this does not happen and the inertia ends after some distance controlled by me after releasing the key.
How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GFX Data, 2022-01-15
@LittleBob

Need momentum, simple AddForce turns on continuous force, so flies away.
More or less like this:

public float thrust = 1.0f;
public Rigidbody rb;

void Start()
{
        rb = GetComponent<Rigidbody>();
        rb.AddForce(0, 0, thrust, ForceMode.Impulse);
        rb.drag = 0.1f; // Убеждаемся что тело будет постепенно останавливаться.
}

S
Sergey Vodakov, 2022-01-14
@WaterSmith

Physics should be known at least in general terms.
With gravity 0, nothing should fall anywhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question