- Home /
How do I detect a collision without affecting the physics?
Hi,
I'm having several GameObjects in my scene, which have the Rigidbody and SphereCollider Components added.
In most cases, they are supposed to collide and affect each other's velocity on impact, just like the standard behaviour. But in some cases, I just want to detect a collision without actually changing the direction or velocity of the involved objects.
I already call the Physics.IgnoreCollision function in OnCollisionEnter, to deactivate the collision detection, but the Objects still give each other at least a little push. How can I prevent that from happening altogether in certain cases?
Answer by duck · Dec 14, 2009 at 09:08 PM
Sounds like you need to set the collider to act as a Trigger. Read about triggers on this page (about 1/3 the way down):
http://unity3d.com/support/documentation/Manual/Physics.html
And you can hook your script into trigger events using these functions:
Answer by duck · Dec 14, 2009 at 11:01 PM
An alternate approach (which might better suit your requirements of having some collisions still act as solid objects) might be to record the current values for the rigidbody's .velocity and .angularVelocity in every FixedUpdate to separate variables.
Then, when a collision is detected, re-set these values to the values recorded on the previous frame (and also deactivate the collisions between those two objects, as you're currently doing).
Hey Duck. This is exactly what I was looking for, but for some reason the solution is not good for me. What I need is to have the collision events to be triggered but withour any real physics concecuence. I need the normal vector, so I cant use triggers, so your solution seemed logical. But when the OnCollisionEnter() is called, the damage is already done. I even try to do it in the FixedUpdate, but with no avail. No matter what I do, you can see the object move a tinsy bit and then move back into its place. Have you been fiddling with this ?
Your answer
Follow this Question
Related Questions
Keep Horizontal Momentum after Jump 2 Answers
How to stop sphere from clipping through cube edges aside from lowering Time.FixedDeltaTime? 1 Answer
Collision.impulse = 0 in OnCollisionStay Kinematic Static collision pair after Update 0 Answers
Player's Rigidbody slides up terrain walls 1 Answer
Ping Pong bat is not detecting the collision with the wall 1 Answer