Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Increase Height of CharacterController Without Jitter?

Discussion in 'Physics' started by vostok4, Jun 3, 2017.

  1. vostok4

    vostok4

    Joined:
    Nov 1, 2015
    Posts:
    74
    Hi, I'm having a problem with crouching in an FPS game.

    I've been adjusting the CharacterController.height in FixedUpdate(), and to crouch the results are OK. On downward motion the camera smoothly falls down as the actual capsule collider is made smaller then quickly floats down.

    However, I have a big problem with increasing the height (standing back up): if I try a 1 frame approach (just height = standingHeight;) then the capsule will intersect with the floor collider, and "jump" out of it, giving me an extremely quick and abrupt (and unusable) standing motion. If I try to lerp the height up to standingHeight, then I get the same behaviour, just with maybe 10 smaller/jerkier steps. I've tried to increase the transform by (0, standingHeight / 2, 0) on the frame of height increase to move up the capsule without snapping through the floor, but that doesn't work.

    Does anyone know a good strategy for implementing crouching? I need to actually shrink my capsule collider because crouched walk lets you get into smaller places.

    Thanks!
     
  2. Firesoft

    Firesoft

    Joined:
    Dec 20, 2016
    Posts:
    308
    Same Problem
     
  3. vostok4

    vostok4

    Joined:
    Nov 1, 2015
    Posts:
    74
    The way I fixed my problem: I have my camera on a child of the FPC / Capsule Collider. I set a box collider trigger for "lower areas", and in that area I ease the camera gameobject down to crouching height, and out accordingly.

    I know its stupid, and it sucks, but it was the quick easy way to achieve good visual results. Maybe other games do the same, I'm not sure. Good luck.
     
    Firesoft likes this.
  4. BoonDev

    BoonDev

    Joined:
    Dec 17, 2013
    Posts:
    4
    You need to adjust CharacterController.center as well when you adjust height (set it to half height + any foot offset you might be using)
     
  5. modernator24

    modernator24

    Joined:
    Apr 7, 2017
    Posts:
    4
    Same problem here. I just try to update "center" of CharacterController but nothing changed.