- Home /
Collision with character controller and cube not working
Hi, I have a character controller with the tag "Player" and a cube called door with the tag "Door", this function isn't working, it is in the doorPhysics.js script for the door. I am trying to simulate a door being opened when the "Player" hits the "Door". Even when I remove the if statement the Debug.Log doesn't work. And I am sure the doorPhysics.js script is linked to the door.
function OnCollisionEnter(col : Collision){
if (col.gameObject.CompareTag == "Player"){
Debug.Log("the door should have rotated");
transform.position = Vector3(-.5,0,0);
transform.rotation = Quaternion.Euler(0,-90,0);
}
}
Look at my comments to the question asked right here
$$anonymous$$y first comment adds a second print to test for the colision before the IF statement. $$anonymous$$y second comment links a couple other places where they talk about character controller collision.
I just tried it, the print statement does not show up. I'll check out the link
Did you ever read through that link and some of the materials it links to? If so did you try any of those solutions specifically the linked materials pointing to the character controller collisions? Unity handles character controller collisions differently than other colliders. You will need to use one of the other methods to capture the collision.
This link explains character controller by comparing it with similar component 'rigid body'. https://www.youtube.com/watch?v=AEPI5rmg3XY
You may want to check these if OnCollisionEnter starts with collision of non-character objects, but not with character object.
Answer by MrSteve1 · Apr 24, 2013 at 04:19 PM
You don't need CompareTag if this script is attached to the door. just col.gameObject.tag == "Player"
Your answer
![](https://koobas.hobune.stream/wayback/20220613100924im_/https://answers.unity.com/themes/thub/images/avi.jpg)