- Home /
How to get a specific contact point from a CharacterController collider hit?
Hi, I am using a CharacterController that is moved via the Move() function. I also have some hit detection using
void OnControllerColliderHit(ControllerColliderHit hit)
{
Debug.Log( hit.normal );
}
If I am running into a wall (and grounded), the output would be :
(-1.0, 0.0, 0.0)
(0.0, 1.0, 0.0)
which I am assuming is outputting both the ground hit and the wall hit. If I am airborne and hit a wall, it will only output (-1.0,0.0,0.0).
My question is how do I retrieve only the hit normal of ONE of the points? All I'm simply trying to do is check if the hit normal.x is == 1 or -1, but if it is grounded, it keeps returning both true and false. Thanks!
Answer by Montraydavis · Nov 01, 2012 at 11:53 PM
It is because most likely it's reading from multiple objects. Maybe the floor? You need to specifically ask for the cube.
if ( hit == {GameObjectLookingFor} )
{
..//do code
}
You say that this only happens when you are not airborne. That's what makes me think it has something to do with reading from both the cube and floor .
I hope that solves your issue .