Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Player Stuck Moving

Discussion in 'Getting Started' started by Themeepclub, Nov 16, 2021.

  1. Themeepclub

    Themeepclub

    Joined:
    Oct 25, 2021
    Posts:
    4
    I've been having this weird problem in Unity where my player keeps moving forward and left as if the W and A keys were stuck. This issue occurred in 2 microgames, the universal render pipeline, and a 2D game with custom code (player just moves left in 2D). I am still able to move the player, but if I let go of keys, it continues to move. In the microgames and pipeline, the problem was only solved if I clicked "maximize on play" then stop and restarted the game. I had no problem playing these same microgames on a different PC. In the 2D game, the issue would stop the second time I tested the game, but if I switched windows and game back, the player would move as soon as I started the game (without me pressing anything). This would occur even if my keyboard and mouse was unplugged. I have also tried reinstalling Unity and Visual Studio as well as restarting my PC. I don't think the issue is with the code or my peripherals, and I have no idea what else it could be.

    I would really appreciate some help!


    Here is the code from the 2D game if you wanted:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerMovement : MonoBehaviour
    4. {
    5.    public float speed;
    6.    private Rigidbody2D body;
    7.  
    8.     private void Awake()
    9.     {
    10.         body = GetComponent<Rigidbody2D>();
    11.     }
    12.  
    13.     private void Update()
    14.     {
    15.         body.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, body.velocity.y);
    16.  
    17.         if (Input.GetKey(KeyCode.Space))
    18.             body.velocity = new Vector2(body.velocity.x, speed);
    19.  
    20.     }
    21.  
    22. }
    23.  
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,761
    Please don't cross post. You've posted this issue several times now. You got a reply here.