- Home /
Collision on character controller (fps player)
I've been trying to work out my way through a simple collision problem.
I have a fps player with a character controller attached to it and I am trying to make it collide with a box. On the box, I have a box collider (is trigger = uncheck), a rigidbody with gravity turned on and this simple script
#pragma strict
function OnCollisionStay(theCollision : Collision) {
if(theCollision.gameObject.name == "fpsplayer"){
Debug.Log("Hit Player!");
}
}
attached to it. When I put this rigidbody over the fpsplayer head it falls and the debug do show collision happens but when I put it in the world and make my player's way to it and make it collide with the box no collision is detected.
Thanks, and a Happy New Year.
Fattie sir please be generous and let the question pass the moderation c:
anyone ? I am stuck since like 20 hours tried everything :/
Answer by clunk47 · Jan 01, 2013 at 06:53 PM
I know that character controller only detects collision while moving, perhaps you could try CharacterController.OnControllerColliderHit.
still don't work
void OnControllerColliderHit() { Debug.Log("Hit!"); }
Use the example I linked you to. You forgot to assign the hit var inside of the method.
void OnControllerColliderHit(ControllerColliderHit hit) { Debug.Log("Hit!"); }
You just just copy and paste from the example in the script reference, then modify it.
Your original post is in JS. $$anonymous$$ake sure you're looking at the right language of the example because void is C#. In JS you would need to use function ins$$anonymous$$d of void.
Found a way around by using trigger and stuff, well I will keep ControllerColliderHit in $$anonymous$$d, thanks anyway.
Answer by sushanta1991 · Jan 02, 2013 at 12:15 PM
Use CharacterController.Move to move your player, other wise you can't detect collision on your Character Controller.