Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Gradual acceleration movement 2D

A topic by Golly G created Feb 23, 2020 Views: 151
Viewing posts 1 to 2

I use Unity and have a basic movement script implemented but I would like to add a acceleration and deceleration movement to the script. 

public float moveSpeed = 5f;
public Rigidbody2D rb;

Vector2 movement;

    // Update is called once per frame
    void Update()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
    }

    void FixedUpdate()
    {
        rb.MovePosition(rb.position + movement * moveSpeed * Time.deltaTime);    
    }

Moderator moved this topic to General Development