- Home /
How can I tell if my character controller is in contact with a wall?
Answer by InfiniBuzz · Jul 12, 2013 at 11:32 PM
This is a duplicate question, however you would go attach a script to your character and add the following function:
// in js:
function OnCollisionEnter (other : Collision)
{
Debug.Log("I collided!");
if (other.gameObject.name == "Wall") {
Debug.Log("Collided with wall!");
}
}
// in c#:
void OnCollisionEnter (Collision other)
{
Debug.Log("I collided!");
if (other.gameObject.name == "Wall") {
Debug.Log("Collided with wall!");
}
}
if you need the information every frame use:
// in C#:
void OnCollisionStay (Collision other)
{
Debug.Log("I'm colliding!");
if (other.gameObject.name == "Wall") {
Debug.Log("Colliding with wall!");
}
}
hope it helps
@InfiniBuzz - This is not going to work with a character controller. See OnControllerColliderHit() for a solution.
Oh right, I didn't realize this is for a character controller
Your answer
Follow this Question
Related Questions
When i jump in front of a wall and going forward, the player go down glitchy (character controller) 2 Answers
Is there a way to make a wallrunning system using the character controller? 1 Answer
character controller go through wall 0 Answers
I need help with adding my character controller to a Character model 2 Answers
CharacterController set the Min Move Distance via Script 1 Answer