- Home /
Having a kinematic rigidbody detect collision with a collider without a rigidbody
Is it possible to have a kinematic rigidbody detect when it has collided with another collider that does not have a rigidbody? (Are these static colliders)?
OnCollisionEnter does not seem to trigger
Answer by Invertex · Apr 19, 2018 at 08:09 PM
In 2017, Unity added the "Contacts Generation" setting in your Project Settings > Physics menu.
You can set this to "Enable Kinematic Static Pairs" to allow kinematic rigidbodies to get callbacks on collisions with static colliders.
There's nothing wrong with being gay so there's no need to say "not gay". But you're welcome.
That didn't work for me., why ? And i can't find another solution on the internet..
Double check your kinematic object and your static collider. Are both on the same layer? The kinematic object has its rigidbody active? In your Project Settings>Physics, is the layer the objects are on set to collider with eachother? Did you put a breakpoint or Debug.Log at the start your OnCollision/Trigger Enter method to see if it's being called at all?
You probably are doing a 2d game here, I tried the same, not working either.
Thanks a lot.. You have saved me weeks :) :D thanks again, this is what I actually want :)
Answer by mustafa · Sep 10, 2013 at 11:45 AM
Yes, you can achieve the effect that you want by make it not kinematic rigidbody and checking all the constraints for freeze position and freeze rotation. This way your rigidbody is not effected by physics but can still detect collision with OnCollisionEnter(Collision c), OnCollisionStay(Collision c) and OnCollisionExit(Collision c)
This should be the accepted answer. The alternative of $$anonymous$$inematic is Freeze contraints and it keep the collider's properties.
I wanted to know something like this. thanks for sharing that nice trick!
THIS is the perfect answer. What he means is:
Turn the Rigidbody Dynamic INSTEAD OF Kinematic
Go to Constraints
Uncheck Freeze Positions X, Y
Check Freeze Rotation Z
Here's the collision matrix from unity docs for clarification.
THIS is the perfect answer. What he means is:
-Turn the Rigidbody Dynamic instead of Kinematic -Go to Constraints -Uncheck Freeze Position X, Y -Check Freeze Rotation Z
And the laws of physics in Unity are held up detecting collisions. The collision matrix from link text is given below for clarification.
Answer by syclamoth · Jan 25, 2012 at 01:49 AM
No, it's not possible to have a kinematic rigidbody detect collisions with static colliders. Look it up in the manual- there's this nice little chart down the bottom that explains all of this.
Is there a workaround then to having a static collider detect the colliding kinematic rigidbody?
I could think of several million reasons off the top of my head why someone might want to detect when a kinematic rigidbody is hitting something, even if normal physics aren't applied, see my answer below.
Well, yeah- you might want to detect when the objects are passing through each other, but they don't hit each other if the rigidbody is kinematic. The key point here is 'Collison' - if you want messages to get sent, make the collider on the rigidbody a trigger, and use the OnTriggerEnter message ins$$anonymous$$d. You won't get point and normal data, or anything else that relies on the physics system, but the signal will work.
OnTrigger only works on the static collider, but what about something that is on the moving platform (ins$$anonymous$$d of having to put a script in all static colliders)
I ended up just using a raycast. Not sure if that will affect performance much
Answer by Kailas · Jan 25, 2012 at 07:56 AM
It isn't directly possible, no.
But if you put another game object under the kinematic rigidbody that contains a trigger with the exact same collider as the parent and a kinematic rigidbody of its own, the trigger will (in theory) receive trigger messages from whatever they hit since they'll always be in the same position.
I have never actually tried this so it might not work if unity decides it doesn't feel like it.
Answer by glitchers · Aug 03, 2016 at 03:13 PM
I had success to get a collision (hit point, normal etc) with a kinematic rigidbody with a trigger collider with the static world collider.
I was using OnCollisionEnter
but that only gave me the collider, not the hit point & normal. Because I was moving the kinematic rigidbody, before I moved it in FixedUpdate
I used Rigidbody.Sweep
which gives has an out for RaycastHit
.
In my tests this gave the same result as the non-kinematic non-trigger rigidbody colliding with the world.
Your answer
Follow this Question
Related Questions
Preventing objects from intersecting with minimal physics 3 Answers
Make isKinematic false when touching a Collider? 1 Answer
Controll squeeze of rigidbody between static collider and kinematic rigidbody. 1 Answer
Object gravity but no collisions 0 Answers
Collisions between two rigidbody's and scripting collisions problem 2 Answers