0
\$\begingroup\$

When a sprite with a box collider 2d hits the game object (rigid body),

the collision detection is fired and I get the event.

However, the sprite moves the rigidbody and I have trouble restoring it back.

I tried to create a collision detection without ridigbody but without success.

Is there a way so that the ridigbody is never moved?

Hint: I can't make it static, since the rigidbody becomes immovable.

\$\endgroup\$
3
\$\begingroup\$

On the GameObjects, you could mark the Is Trigger box in the inspector, or from a script, do: collider.isTrigger = true. This will yield events in a similar way, but use the OnTrigger methods instead of the OnCollision methods, as described here.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ using isTrigger means actually that onTrigger not onCollision events will be called? \$\endgroup\$ – mirzahat Dec 24 '14 at 14:51
  • \$\begingroup\$ @mirzahat Correct. You can still handle events in a similar way. One distinction to note though, is OnTriggerEnter2D will have an object of type Collider2D as an argument, as opposed to OnCollisionEnter2D, which would get passed a Collision2D. \$\endgroup\$ – lase Dec 24 '14 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.