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.

Question Why this happens?

Discussion in 'Physics' started by LazyGhost15, Apr 2, 2023.

  1. LazyGhost15


    Feb 12, 2022
    I copied a moving system from YouTube to improve my chrecter movement. But the chrecter always moves a little and then stops and I dont know why. I think it might be connected to the X velocity in the rigidbody because the charecter always stops when the velocity drops to 0.
    This is the script:
    Code (CSharp):
    1.  Speed = _moveInput.x * MaxSpeed;
    3.         if (Input.GetKey(KYBRight))
    4.         {
    5.             IsFacingRight = true;
    6.             IsMoving = true;
    7.             float SpeedDif = Speed - rigidbody2.velocity.x;
    8.             float movement = SpeedDif * accelaration;
    9.             rigidbody2.AddForce(movement * Vector2.right);
    10.             print(movement);
    12.         }
    And here's a video of the problem:
  2. karliss_coldwild


    Oct 1, 2020
    Is the ground made from multiple box colliders? What is the shape of collider of player character?

    Without knowing more my best guess is that corner of box collider is getting caught on the seam between multiple ground colliders.

    You can mitigate it by making the corners of box colliders slightly round using edgeRadius property . It will change box with sharp corners, into a box with rounded corners. Just like in real life stuff with round corners is more likely to slide smoothly. Link to scripting API but it can also be set in the editor. As you increase the radius you might need to decrease the box collider size to maintain the overall dimensions.