Before updating to Windows 10 you may need to return your Pro license. More information here

Deform Charater controler Collider acording to stance

I've been messing around with character controller and it's colliders

The idea is to deform the collision on the character when the characters changes stance (i.e stand, crouch, Prone etc.)

I've tried adding different colliders to the characters bones. but the character also makes use locomotion, so the rays casted from locomotion starts clashing with the colliders.

I've also tried scripting to the character controller to change size when the character changes stance, but with no results.

Any suggestion is appreciated. :)

more ▼

asked Apr 21, 2011 at 09:12 AM

avatar image

6 9 6 12

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I don't know if it will play well with locomotion or not, but I've tried it, and scripting the character controller collider DOES work... At least changing the height and center of the collider.

I created a small example project, but can't upload it here, so if you need it send me your email using a private message or something.

The code attached to my character controller:

using UnityEngine; using System.Collections;

public class Crouch : MonoBehaviour { public Transform tHead;

 private Vector3             _v3InitialPosition;
 private Vector3             _v3CrouchingPosition;
 private CharacterController _characterController;
 private float               _fInitialControllerHeight;
 private float               _fCrouchingControllerHeight;
 private Vector3             _v3InitialControllerCenter;
 private Vector3             _v3CrouchingControllerCenter;

 void Start()
     _v3InitialPosition = tHead.localPosition;
     _v3CrouchingPosition = _v3InitialPosition + Vector3.down;
     _characterController = GetComponent(typeof(CharacterController)) as CharacterController;
     _fInitialControllerHeight = _characterController.height;
     _fCrouchingControllerHeight = _fInitialControllerHeight - 1f;
     _v3InitialControllerCenter = _characterController.center;
     _v3CrouchingControllerCenter = _v3InitialControllerCenter + Vector3.down * 0.5f;

 void Update () 
     if (Input.GetKeyDown(KeyCode.Space))
         tHead.localPosition = _v3CrouchingPosition;
         _characterController.height = _fCrouchingControllerHeight;
         _characterController.center = _v3CrouchingControllerCenter;

     if (Input.GetKeyUp(KeyCode.Space))
         tHead.localPosition = _v3InitialPosition;
         _characterController.height = _fInitialControllerHeight;
         _characterController.center = _v3InitialControllerCenter;


more ▼

answered Apr 21, 2011 at 12:55 PM

avatar image

1.8k 6 10 24

Thanks your answer, i've tried this now and it's works, but when ever i apply it my character ended up falling throw the floor.

But I don't need this function any more as i started adding Collision boxes as Triggers instead(and shrinking the Character controller) which solved most of the problems i had with the Colliders.

Thanks anyways.

Apr 23, 2011 at 08:19 AM Aslan
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Apr 21, 2011 at 09:12 AM

Seen: 1440 times

Last Updated: Apr 21, 2011 at 09:12 AM