Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

More smooth movement in 2D

Discussion in '2D' started by PlyfexHD, Jul 5, 2020.

  1. PlyfexHD

    PlyfexHD

    Joined:
    Jul 5, 2020
    Posts:
    4
    Hello, I want a more smoother movement in my 2D game. I created a rigidbody 2D and changed the Gravity to 0 because I dont want that I fall down. When I move it is smooth but I want that the movement is more delayed. For example I press A Im going left then I release the button but Im still moving(for 1-2 seconds) in that way.

    I hope you could understand what I try to do, my script for moving the player is here, I dont use GetAxisRaw because it stops immediately when I release so i choosed only GetAxis.

    Code (CSharp):
    1. public class bewegen : MonoBehaviour
    2. {
    3.  
    4.     public float speed = 4.0f;
    5.  
    6.     // Update is called once per frame
    7.     void Update()
    8.     {
    9.        
    10.     }
    11.  
    12.     private void FixedUpdate()
    13.     {
    14.  
    15.         Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
    16.         transform.position += movement * speed * Time.deltaTime;
    17.        
    18.     }
    19. }
    20.  

    I'm new to coding so please dont be you know....

    Thanks for your answers.
     
  2. PlyfexHD

    PlyfexHD

    Joined:
    Jul 5, 2020
    Posts:
    4
    i found a solution....