- Home /
C# Character Controller Collision If Statement
Hi everyone, can a character controller use an if statement to see if it collides with another object or is it not that simple? I know that character controllers and colliders use functions to detect this but I would like a simple if statement to check for a collision if possible.
Answer by shaderop · Jul 10, 2013 at 07:00 PM
You can try using Physics.CheckCapsule to do a simple true or false check.
Can that be used for Character Controllers? That sounds like it's for capsule colliders specifically.
I'm getting errors from the console saying identifier expected what is wrong?
public CharacterController charcontroller;
bool CorridorIsWideEnough(charcontroller.height, charcontroller.center, charcontroller.radius) {
return Physics.CheckCapsule(charcontroller.height, charcontroller.center, charcontroller.radius);
}
Answer by Dothackking · Jul 11, 2013 at 11:43 PM
void OnControllerColliderHit (ControllerColliderHit hit)
{
if(hit.gameObject.tag == "playerDoor")
{
currentDoor = hit.gameObject;
Door (doorOpenSound, true, "dooropen", currentDoor);
}
}
It's not "in an if" but there is a nice if inside of it OnControllerColliderHit only handles Character Controllers I believe.