- Home /
How to make kinematic rigidbody react to some collisions
I have a number of objects with rigidbodies on my scene. Some of them are kinematic to make them stable. However, if a kinematic object is hit by a special type of object, it needs to react as if it was not kinematic, i.e., it needs to become non-kinematic, and react to the same collision that makes it non-kinematic.
If I use
OnCollisionEnter(Collision collision)
{
rigidbody.isKinematic = false;
}
the object becomes non-kinematic, but fails to react to that collision. My guess is that the collision has already begun, changing "isKinematic" in "OnCollisionEnter" is too late.
Which means, I somehow need to know the collision right before it really happens.
Any suggestions?
Answer by Jeff-Kesselman · Jun 07, 2014 at 02:57 PM
Rather then making it kinematic, you can give it its own layer and use the Physics settings to control what other layers it interacts with.
http://docs.unity3d.com/Manual/class-PhysicsManager.html
Note that this will ALSO prevent it from applying forces to anything it is set not to interact with.
If thats not what yo want then yo hare likely into scripting specific application of forces from specific objects.
I need other objects to hit kinematic ones, but kinematics should not react to collisions and stand still, unless the object hitting the kinematic one is of special type.
If I use layers, they won't hit each other at all.
Answer by oasisunknown · Jun 08, 2014 at 07:50 PM
you could use your code then add a force to the object yourself to get it moving. (series of events.) 1. gets hit 2. turns itself non kinematic 3. gives itself a large push in the right direction. 4. everything else that happens.
Unfortunately, I have to make sure both objects (the one hitting and the one getting hit) react as if nothing was special. I don't think it is feasible to mimic the reactions of objects as if physics engine was in use.
Answer by legion_44 · Jun 08, 2014 at 08:32 PM
I think You can make another Collider that will be trigger and set it to be bigger than actual collider (the bigger velocities, the bigger offet You will need to use) and then in OnTriggerEnter set rigidbody to non-kinematic. This should work.
This can make objects collide even if they are not going to collide in their actual trajectories. I am thinking of using an extra (invisible) object that is always where the actual object will be in the next frame. It is similar to this, but with higher possibility. There can be some extreme cases where it will malfunction, but I guess there is no better way.
Answer by rhbrr5hrfgdfgw · Jun 08, 2014 at 09:29 PM
function OnCollisionEnter(collision : Collision) {
rigidbody.isKinematic = false;
}
Thanks, but the problem is not caused by a faulty script.
Answer by rhbrr5hrfgdfgw · Jun 08, 2014 at 09:37 PM
function OnCollisionEnter(collision : Collision) {
rigidbody.isKinematic = false;
}
Your answer
Follow this Question
Related Questions
Collision Only being detected on one of the objects involved in the collision - C# 0 Answers
what object hit me? easy rigidbody question 1 Answer
[SOLVED] Desactivate pushing forces between two objects 2 Answers
Enemy rigidbody and bullet collisions 1 Answer
Child Rigid Body collision problem 2 Answers