x


Collision wont be detected

I have a Child named Waypoint of the game object player and the other child PlayerObj moves towards Waypoint. The Enemy has a mesh on it with the renderer turned off and the trigger turned on(the script attached to it is below). The problem is when the PlayerObj collides with the mesh on the enemy it doesn't recognize it, any idea why would be very helpful.

var Target : String;

function OnTriggerEnter (Enter : Collider)

{

 if (Enter.gameObject.tag == "Player")
 {
     Debug.Log("Colided");
     var contact : String = Enter.transform.name;
     Target = contact;

     transform.root.gameObject.SendMessage ("AttackingOn");
     transform.root.gameObject.SendMessage ("TargetNumber", Target);
}

}

more ▼

asked Jul 24 '12 at 06:53 PM

Zacharianinjaa gravatar image

Zacharianinjaa
1 4 7

does PlayerObj has a Rigidbody component attached?

Jul 24 '12 at 09:32 PM ScroodgeM

no it does not at the moment

Jul 24 '12 at 09:36 PM Zacharianinjaa

1st thing that comes to my mind is if all the objects have colliders.

after that check ur code without the condition if. if it works try placing the condition agian, and make sure ur tag is correct.

try to print something inside the if to see it it works like print(1); this will make the console print 1 if the condition works.

gl

Jul 24 '12 at 10:11 PM Mander
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html

Note that collision events are only sent if one of the colliders also has a non-kinematic rigid body attached.

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnTriggerEnter.html

Note that trigger events are only sent if one of the colliders also has a rigid body attached.

more ▼

answered Jul 24 '12 at 10:40 PM

ScroodgeM gravatar image

ScroodgeM
7.6k 2 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3568
x1765
x516

asked: Jul 24 '12 at 06:53 PM

Seen: 239 times

Last Updated: Jul 24 '12 at 10:40 PM