- Home /
character collider colliding with another character collider
im using the characterController to move me(my players character), and my ai characters, and they will recognize collision with each other, but how do you reference the ai's gameObject that im colliding with to, in this case Destroy() the AI my Player collided with?
function OnControllerColliderHit(hit:ControllerColliderHit){ if(hit.rigidbody.tag=="Enemy"){ print("hit");//wont print Destroy(hit.gameObject); } }
how do i check if what i run into is my ai character tagged Enemy?
Answer by jonas-echterhoff · Aug 19, 2010 at 09:56 AM
I guess your problem may be that the object which you are colliding with is a CharacterController, not a rigidbody, so hit.rigidbody
is not valid. Try checking the value of hit.gameObject.tag
instead.
hit is of type ControllerColliderHit "OnControllerColliderHit(hit:ControllerColliderHit){", i mean to ask how can i reference the hit's gameObject component, to Destroy it? i am unclear about the link of ControllerColliderHit to the gameObject hit
Destroy( hit.gameObject )
info: http://unity3d.com/support/documentation/ScriptReference/ControllerColliderHit-gameObject.html
Your answer
Follow this Question
Related Questions
OnControllerColliderHit -> GetComponent on collided object not working 1 Answer
Detecting collisions with OnControllerColliderHit when not moving 0 Answers
OnControllerColliderHit won't trigger if not moving 2 Answers
Collision with 2 CharacterControllers not precise 1 Answer
Character Controller problem 1 Answer