Search Unity

Question Resizing a capsule collider at runtime

Discussion in 'Physics for ECS' started by cranky, Apr 2, 2020.

  1. cranky

    cranky

    Joined:
    Jun 11, 2014
    Posts:
    180
    Hey guys,

    I am working on character controllers in ECS and currently implementing crouching. I would like to resize the collider, but I am not seeing being able to do so, aside from creating a new collider every frame the crouch state is animating. Is this really the only option? Thanks!
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Yeah, unfortunately there is not option other than to set a new collider. But a small optimization might be to store 2 colliders, original one and the crouching one, and then just switch between them. That way you won't need to instantiate it every frame...
     
  3. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    If the collider is a simple one, e.g. a capsule collider, you can tweak the underlying geometry. Check out the 5b. Change Collider Size in the samples. The associated script will act as a reference.
    @petarmHavok's suggestion is the most generic approach though.
     
  4. cranky

    cranky

    Joined:
    Jun 11, 2014
    Posts:
    180
    Looks very promising, thank you!
     
  5. federicojurjo

    federicojurjo

    Joined:
    Sep 22, 2021
    Posts:
    1
    Hi, maybe this will help other people with the same question.

    A difference box collider, capsule collider has the possibility of modifying the radius and height.

    the code to access this is:
     

    Attached Files:

  6. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    629
    This has nothing to do with Unity Physics. Your suggestion isn’t helpful here.
     
    Kmsxkuse likes this.