I
I
Ilya Valferov2021-02-10 18:17:41
Unity
Ilya Valferov, 2021-02-10 18:17:41

How to make a smooth movement of the character in Unity (With acceleration and fading)?

It is necessary to make a smooth movement of a 2D character
The code written below starts to move it abruptly and when the button is released it stops abruptly
I want the character to accelerate and stop in an instant
How to do this?
My code:

public class movement : MonoBehaviour
{
    private Rigidbody2D rb;
    public float speed;
    float move;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    void FixedUpdate()
    {
        move = Input.GetAxis("Horizontal");
        rb.velocity = new Vector2(move*speed, rb.velocity.y);
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question