- Home /
OnControllerCollider hit called when moving away from a surface
I am making a game where the player aims and fires a spherical projectile which sticks to certain surfaces. I am using a Character Controller and I am using OnControllerColliderHit to register collisions.
It works correctly except when the projectile tries to launch from a ceiling. When I launch the projectile from the ceiling, the projectile moves slightly but then OnControllerColliderHit registers a collision and the projectile remains stuck to the surface.
The bug only occurs when the surface normal has a y value between -0.3 and -1.0. The closer the value is to -1.0, the more extreme the bug becomes. When the value is -0.3 the bug only occurs when the projectile is fired at certain angles, however, when the value is -1.0 the bug always occurs.
I did consider that it might be caused by using a sphere instead of a capsule, but the bug remains even when I use a capsule projectile. I also tried adjusting the skin width of the CharacterController, but this had no effect.
void OnControllerColliderHit(ControllerColliderHit hit)
{
switch(hit.gameObject.tag)
{
case "Bouncy":
Vector3 fU = Vector3.Dot(control.velocity.normalized, hit.normal) * hit.normal;
Vector3 fW = control.velocity.normalized - fU;
Vector3 vecDirection = fW - fU;
vecDirection.Normalize();
scrMove.resetOnBounce();
scrMove.setMoveVar(vecDirection);
StateMachine.requestChange(StateMachine.State.ACCELERATE);
break;
case "Sticky":
StateMachine.requestChange(StateMachine.State.LAND);
break;
}
}
}
Your answer
Follow this Question
Related Questions
Any way to ignore collision between rigidbodies and colliders/character controllers? 1 Answer
Collider not continuing to Ignore CharacterController after center changes. 0 Answers
OnCollisionEnter not working 1 Answer
Stop Root Motion if out of boundaries? Simple Wall Climbing System 1 Answer
How to trigger different animations depending on where a gameobject collides? 1 Answer