- Home /
how to check if one object is colliding with another
hey guys,
i was just wondering if there was a simple way to check if:
an object is colliding with another certain object,
and to check if an object is colliding with any object.
thanks
-Grady
Answer by 198boblob · Jun 30, 2011 at 02:18 AM
THE FOLLOWING SCRIPT IS JAVA SCRIPT
//start of script
var otherObjectTag = "Object";
function OnCollisionEnter (hit : Collision)
{ ///you are colliding
Debug.Log("CollidingWithAnything");
if(hit.gameObject.tag == otherObjectTag){ //now colliding with certain object
Debug.Log("Colliding With Certain"); }
}
///end of script
DO NOT COPY THIS OR ANYTHING PAST
hope it works
you have to add a collider besides the Character Controller for this to work but that shouldnt mess anything up. just go to Component>Physics>(Id recomend capsul collider) then make sure the capsule collider is bigger then the CharacterController
Sorry, it doesn't work for me. Translated it to c# so I have something like this:
void OnCollisionEnter (Collision c) {
if (playerObject!=null){
if (c.gameObject.tag == playerObject.tag){
tempest = true;
}
}
}
playerObject is object set via Inspector and it is set to object it need to collide with. "tempest" variable is used in OnGUI to show text that we collided.
Your answer
Follow this Question
Related Questions
Collision detection not working properly with 2D sprites 1 Answer
WTF is wrong! OnTrigger, OnCollision, nothing working! 2 Answers
Can an object to transfer to another as it increases your speed? 1 Answer
Spawning and health script not working with collider? 1 Answer
Collision detection problem 1 Answer