- Home /
Question by
JoRouss · Apr 08, 2014 at 09:27 AM ·
collisionphysicscharactercontroller
CharacterController collision disabled when modifying center
I'm using the mecanim root motions and a CharacterController. Here is a small portion of my code where i'm trying to make the collider go down :
private CharacterController CC;
private float defaultColliderY;
void Start ()
{
CC = GetComponent<CharacterController> ();
defaultColliderY = CC.center.y;
}
void FixedUpdate ()
{
if(CC.center.y != defaultColliderY)
CC.center = new Vector3(0, defaultColliderY, 0);
}
The previous code works.
The problem is, when I remove the "if" statement (so I change the center value on every FixedUpdate), my CharacterCollider will let me go through any objects and my character will move faster than it should.
Looks like it won't detect collisions DURING the "frame" it is modified...
I will need to change it often to follow a curve or a formula.
Can somebody explain that weird behavior to me? Or share a workaround?
Thank you very much
Comment