Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Launched into the air when colliding with wall

Discussion in 'Physics' started by JackyOHare, Jul 24, 2020.

  1. JackyOHare

    JackyOHare

    Joined:
    Oct 6, 2018
    Posts:
    1
    Sorry if this is a really basic question but I'm lost on how to fix this.

    So when I'm pressing against a wall and change the height of the capsule collider; I get launched into the air or pushed back from the wall for no reason. I have no clue what could be causing and would be grateful if somehow could explain what I messed up on. Thanks!

    Code (CSharp):
    1.   private void FixedUpdate()
    2.     {
    3. //Starting height is 2 then changes to 1
    4.         if (Input.GetKeyDown(KeyCode.LeftShift) && isCrouching == false)
    5.         {
    6.  
    7.             isCrouching = true;
    8.             ShrinkCollider.height = 1f;
    9.         }
    10.         else if (Input.GetKeyUp(KeyCode.LeftShift) && isCrouching == true)
    11.         {
    12.  
    13.             isCrouching = false;
    14.             ShrinkCollider.height = 2f;
    15.         }
    16.     }