Lagging with Player Movement

So I was watching Lesson 91 in Rick’s Complete C# Unity 2D. In this lesson, he was trying to make the player move by keyboard. So you will be able to make the fighter move by pressing up and down, left and right; but, as the fighter moves, you can observe there is some lagging with the movement. It seems to me that the running of the Update method won’t be able to catch up with the representation of the fighter, so there’s that lagging. Do we have any method solving this issue so that when we press the keys, the movements go smoothly?

Thank you,

Hello! Welcome back to the community!

It is not the Update method causing this, actually Update is your best bet for input, if you place it anywhere else it might feel weird or not work sometimes.

If you want sharper movement try using Input.GetAxisRaw instead of Input.GetAxis, the first will return an int while the other returns an increasing float, hence the lagging.

Hope this helps.

1 Like

Hi, idk what you mean exactly, lag could mean your pc is having a bit of troubles.
Good way to test that is build for windows and play it then.

If you mean the movement isnt very responsive, you could try RigidBody movement.

like this;

or this

    float speed = 5f; 
    Rigidbody m_Rigidbody;

    void Start()
        //Fetch the Rigidbody from the GameObject with this script attached
        m_Rigidbody = GetComponent<Rigidbody>();

    void FixedUpdate()
        //Store user input as a movement vector
        Vector3 m_Input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

        //multiply the direction by an appropriate speed.
        m_Rigidbody.velocity = m_Input * speed; 

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms