Search Unity

Bug Unity Editor Linux - Player movement bug

Discussion in 'Editor & General Support' started by LetmeDwight, Jan 9, 2022.

  1. LetmeDwight

    LetmeDwight

    Joined:
    Apr 9, 2020
    Posts:
    125
    I use Unity 2020.3.17f1 LTS. If I run my game in the Unity Editor and try to walk around with WASD it works normal like it should, if I also press Shift to run with WASD, it works still normal as long I realese the Shift Button before of the WASD button. But if I realese the WASD Buttons and the Shift after WASD, the player walks infinity long in the last direction of the last pressed WASD Button (If I walked forward left with "W + A" I will keep walking forward + Left if I realese the Shift button after the W and A Button.
    This issue will not appear on the exported game and only happens in the Editor on Linux.
    When I was working on this project on my Windows 10 a few weeks ago, this problem never existed and I have been working on this game on Windows 10 for a year. Only after I pulled a backup of this project on my Ubuntu did this problem arise, which is only limited to the Unity Editor and not on the exported game!
    I also use Api Compatibly Level: ".NET 4.x" and the: "Input System Package (new)"

    That's the Screenshot of my input-actions:
    Screenshot from 2022-01-09 15-39-33.png

    That is my Movement Script if it should be helpful:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using BayatGames.SaveGameFree;
    5. using UnityEngine.InputSystem;
    6. using UnityEngine.InputSystem.Interactions;
    7.  
    8. public class PlayerController : MonoBehaviour
    9. {
    10.     // Can be used to block the movement while the menu is open...:
    11.     public bool MovementAllowed = true;
    12.  
    13.     [SerializeField] Transform playerCamera = null;
    14.     public float mouseSensitivity;
    15.     private float crawlspeed = 0.4f;
    16.     private float crouchspeed = 0.4f;
    17.     private float walkspeed = 1.3f;
    18.     private float runspeed = 2.8f;
    19.     private float gravity = -13.0f;
    20.     [Range(0.0f, 0.5f)] float moveSmoothTime = 0.13f;
    21.     [Range(0.0f, 0.5f)] float mouseSmoothTime = 0.01f;
    22.  
    23.     bool lockCursor = true;
    24.     float cameraPitch = 0f;
    25.     float velocityY = 0f;
    26.     CharacterController controller = null;
    27.     Vector2 currentDir = Vector2.zero;
    28.     Vector2 currentDirVelocity = Vector2.zero;
    29.     Vector2 currentMouseDelta = Vector2.zero;
    30.     Vector2 currentMouseDeltaVelocity = Vector2.zero;
    31.     private Animator animcontroller;
    32.  
    33.  
    34.     autocrawl_twoDimensionalAnimationStateController isInATriggerSCRIPT;
    35.     void Start()
    36.     {
    37.         isInATriggerSCRIPT = GetComponent<autocrawl_twoDimensionalAnimationStateController>();
    38.  
    39.         animcontroller = GetComponent<Animator>();
    40.         controller = GetComponent<CharacterController>();
    41.         if (lockCursor)
    42.         {
    43.             Cursor.lockState = CursorLockMode.Locked;
    44.             Cursor.visible = false;
    45.         }
    46.     }
    47.     ////////// New Input System Anfang //////////////////
    48.     private PlayerActionControls _controls1;
    49.  
    50.     private void OnEnable()
    51.     {
    52.         _controls1.Enable();
    53.     }
    54.     private void OnDisable()
    55.     {
    56.         _controls1.Disable();
    57.     }
    58.     void Awake()
    59.     {
    60.         _controls1 = new PlayerActionControls();
    61.  
    62.         mouseSensitivity = SaveGame.Load<float>("MeineMausEmpfindlichkeit");
    63.         // Sicherheits Mindestbeschleunigung (Damit das Bild nicht stehen bleibt und man weis das es and der Mausgeschwidigkeit liegt!!!
    64.         if (mouseSensitivity < 0.02f)
    65.         {
    66.             mouseSensitivity = 0.02f;
    67.         }
    68.         mouseSensitivity = mouseSensitivity * 5f; // "5" Ist der Faktor mit dem sich der Slider multipliziert fuer die endgueltige Mausgeschwidigkeit...
    69.         //Debug.Log("mouseSensitivity = " + mouseSensitivity);
    70.     }
    71.  
    72.  
    73.     ////////// New Input System Ende //////////////////
    74.     // W,A,S,D Controls
    75.     void UpdateMovement()
    76.     {
    77.         // Hollt den Vector2 hier rein:
    78.         Vector2 movementInput = _controls1.Player.Movement.ReadValue<Vector2>();
    79.         float xInput = movementInput.x;
    80.         float yInput = movementInput.y;
    81.         bool isCrouching = _controls1.Player.Movement_Crouch.ReadValue<float>() != 0;
    82.         bool isSprinting = _controls1.Player.Movement_Run.ReadValue<float>() != 0;
    83.  
    84.  
    85.  
    86.         Vector2 targetDir = new Vector2(xInput, yInput);
    87.         targetDir.Normalize();
    88.         currentDir = Vector2.SmoothDamp(currentDir, targetDir, ref currentDirVelocity, moveSmoothTime);
    89.         if (controller.isGrounded)
    90.         {
    91.             velocityY = 0.0f;
    92.         }
    93.         velocityY += gravity * Time.deltaTime;
    94.         Vector3 velocity = (transform.forward * currentDir.y + transform.right * currentDir.x);
    95.  
    96.         //Debug.Log("Gerade Trozdem = X: " + xInput);
    97.         //Debug.Log("Gerade Trozdem = Y: " + yInput);
    98.         if (isInATriggerSCRIPT.isInATrigger) //Crawling
    99.         {
    100.             //Debug.Log(" UNDER THE BED!!");
    101.             velocity *= crawlspeed;
    102.         }
    103.         else
    104.         {
    105.             // Animationszuweisung:
    106.             if (isSprinting)
    107.             {
    108.                 if (!isCrouching)
    109.                 {
    110.                     // Geht sicher das es fuer diese Animationen keine Seitliche Bewegungen gibt!
    111.                     if (yInput > 0.7f)
    112.                     {
    113.                         //Debug.Log("RunAktiv = X: " + xInput);
    114.                         //Debug.Log("RunAktiv = Y: " + yInput);
    115.                         velocity *= runspeed;
    116.                     }
    117.                 }
    118.             }
    119.             else if (xInput != 0f || yInput != 0f) // Solange zumindest eine Bewegungsrichtung noch aktiv ist...
    120.             {
    121.                 //Debug.Log("WalkAktiv = X: " + xInput);
    122.                 //Debug.Log("WalkAktiv = Y: " + yInput);
    123.                 velocity *= walkspeed;
    124.             }
    125.  
    126.             if (isCrouching) // Wenn "STRG" gedrueckt, und keine bewegungsrichtung aktiv ist:
    127.             {
    128.                 //Debug.Log("CrouchAktiv = X: " + xInput);
    129.                 //Debug.Log("CrouchAktiv = Y: " + yInput);
    130.                 velocity *= crouchspeed;
    131.             }
    132.         }
    133.  
    134.      
    135.  
    136.         velocity += Vector3.up * velocityY;
    137.         controller.Move(velocity * Time.deltaTime);
    138.     }
    139.  
    140.     // Maus Umschauen
    141.     void UpdateMouseLook()
    142.     {
    143.         Vector2 targetMouseDelta = _controls1.Player.Camera_Movement.ReadValue<Vector2>();
    144.  
    145.         currentMouseDelta = Vector2.SmoothDamp(currentMouseDelta, targetMouseDelta, ref currentMouseDeltaVelocity, mouseSmoothTime);
    146.  
    147.         cameraPitch -= currentMouseDelta.y * mouseSensitivity;
    148.         cameraPitch = Mathf.Clamp(cameraPitch, -60.0f, 80.0f); //"-60" = Zur Decke gucken // "80" = Nach unten
    149.  
    150.         playerCamera.localEulerAngles = Vector3.right * cameraPitch;
    151.  
    152.         transform.Rotate(Vector3.up * currentMouseDelta.x * mouseSensitivity);
    153.     }
    154.  
    155.     void Update()
    156.     {
    157.         // if the player opens the menu for example, the player should no longer move:
    158.         if (MovementAllowed)
    159.         {
    160.             UpdateMouseLook();
    161.             UpdateMovement();
    162.         }
    163.     }
    164. }
     
    Last edited: Jan 9, 2022
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
  3. LetmeDwight

    LetmeDwight

    Joined:
    Apr 9, 2020
    Posts:
    125
    I know this is not the fault of my code because it have no impact on the exported game.
    Also I used a older backup of my project to make sure that this is not a bug a my never scripts and I was still right because the problem on the editor was still there even on my older project backups that worked fine before.
    My guess is that this error is related to the Unity Editor itself from the Linux version because I never had this problem on the Windows version.