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. Dismiss Notice

Question My character continues to move for a little while after I lift the WASD/arrow keys?

Discussion in 'Scripting' started by jamesanders73, Dec 4, 2020.

  1. jamesanders73

    jamesanders73

    Joined:
    Aug 8, 2020
    Posts:
    2
    I'm pretty new to coding, and using multiple tutorials compiled this code (I wanted to avoid if statements while also normalizing the move vector so diagonal motion wouldn't be so fast):


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class movingdw : MonoBehaviour
    {
    public float mSpeed;
    // Start is called before the first frame update
    void Start()
    {
    mSpeed = 3f;
    }
    // Update is called once per frame
    void Update()
    {
    Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
    move = move.normalized * Time.deltaTime * mSpeed;
    transform.Translate(move);
    }
    }



    However, when I use this, my character continues to move for a little bit (a quarter to half of a second) after I lift the WASD/arrow keys. If it helps at all, I'm using a rigidbody, not a character collider, and I have all the default preferences/project settings.
     
  2. CashCache

    CashCache

    Joined:
    May 16, 2016
    Posts:
    11
    I'm definitely no expert, but check to see if your rigidbody is set to interpolate or not. And if so, turn it off as a test.
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Project Settings -> Input Manager

    (edit: woah, how did that arrow came to be? all i did is a dash - and one of those > )


    select your axis (Vertical and Horizontal) and make the gravity super high (like 1000)

    it's simulating a joystick being released and taking a second or so to get back to center.
     
  4. jamesanders73

    jamesanders73

    Joined:
    Aug 8, 2020
    Posts:
    2
    My interpolation is set to "none," but I tried changing the gravity in Input Manager and it fixed the problem! Thank you so much!