OnTriggerEnter2D fires multiple times

I have game in Unity 4.3 2D and I encounter this problem.

I have one object with box collider 2d, with a trigger and rigidbody 2d.

Another object with box collider 2d, with a trigger. I have attached a simple script to detect OnTriggerEnter2D to this object.

void OnTriggerEnter2D(Collider2D col)
	{
		
		print("OnTriggerEnter2D " + Time.time);
		
		
	}

When I moved the 2nd object I expected trigger to fire once when it collide with 1st object. But it keeps on firing as long as I move the 2nd object while it is collided with the 1st object. Almost like OnTriggerStay …

I am completely puzzled by this behavior. Is this normal for 2D or there is something wrong?
I have attached simple project to explain what is happening.

I noticed if I moved the rigidbody object it works as expected, but if i move the trigger it behave this way…

[18505-triggertest.zip|18505]

I'm interested in this question. I have a project where it used a 3d rigidbody, but now I translated everything to physics2d and this part is the only thing that behaves completely different from my previous implementation.

2 Answers

2

The project attached has 2 scripts: GameController and Bullet, neither have any OnTriggerEnter2D function… Also, the Bullet prefab has a child plane with a mesh collider. 2D Physics require 2D colliders, so the spheres need CircleCollider2D, not SphereCollider. The plane child of the bullet prefab needs the OnTriggerEnter2D function attached, and needs a 2D collider component as well. Trigger requires one of the objects to be a non kinematic rigidbody, I’d do this on the bullet, since it’s moving. I’ve got it working on my end, I’ve attached the fixed project, hope it works well on your end.link text

EDIT: Wrong project was attached to original question initially, keeping information above for general information, working solution for specific question below:

It’s because you don’t have a Rigidbody2D component attached to the bomb. I attached that component to the bomb and copied the parachute’s rigibody2D component values to the bomb’s and presto. I just decided to make sure each object had the same components and they didn’t, this seems to work, hope it works for you as well.

bomb object is colliding with the parachute. there are only 2 objects in the test scene. If I moved the rigid body object things work as expected. When I moved the trigger object it work this way ....

Do either of the object have children or parents?

They don't have children or parents. You can check the attached project

Any idea why this is happening?

Can anyone provide some help on this?

look at that