1
\$\begingroup\$

Gif of the problem

  • In my game I can throw a hammer. The hammer moves based on physics in Unity.
  • The hammer destroys the first object it touches. I want it to continue moving as though it didn't touch anything when this happens.
  • To try and achieve this, I made it destroy objects using a separate, larger trigger collider, intending to destroy the object before the physical collision occurs.
  • However, when moving at very high speeds (as in the GIF), both colliders hit at once, so the hammer moves and the object deletes.

How can I prevent the hammer from moving when/before the trigger occurs, or (I suppose more realistically) "reverse" the movement such that there's no perceptible collision?

I tried using the impulses from each of the contacts in the collision to apply forces in reverse, but didn't really understand what I was doing and ultimately failed.

NOTE: I cannot simply disable the physics collider, because it doesn't destroy everything.

\$\endgroup\$
1
  • \$\begingroup\$ Have you considered using physics layers and the collision matrix, so that the non-trigger collider will only collide with things the hammer can't destroy? \$\endgroup\$
    – DMGregory
    Jul 31 '19 at 11:09
1
\$\begingroup\$

I assume you’re handling either OnTriggerEnter or OnCollisionEnter. Try capturing RigidBody.velocity in there, then set a flag to set the RigidBody.velocity to the captured Vector3 in the next FixedUpdate.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .