- Home /
Any way to gracefully detach object with Unity physics?
Hi, I'm having an issue where I have a Rigidbody attached to a parent, and then I want to unparent it and add force.
First I tried having a kinematic rigidbody when it's being held that is turned into a kinematic rigidbody when it is thrown. But when it is marked as kinematic the physics go WILD, even if I ignore collisions between the player and the projectile and set the velocity manually to 0 and even without adding any force.
The same thing happens if I use constraints instead of kinematic. When I remove the constraints (when it's time to throw the object), the projectile goes crazy and launches all over the map, even if I don't add any force to it.
Does anyone have any idea why this would be the case and what is the best way to "throw" a Rigidbody that was formerly attached to another one?
Answer by Jordash · Oct 14, 2018 at 03:38 AM
Make sure it is set to kinematic when parented to the other object. I've found objects seem to build up any forces acted on them only to release them all when they are unconstrained.
Thanks, but I need the object to be non-kinematic when it is released from the other object, hence my issues here :-( any ideas along those lines? $$anonymous$$y findings line up with yours.
I wish there was a way to Rigidbody.ClearForces or Rigidbody.Stop.
I meant have it be kinematic before it is released, then set it to non-kinematic at the same time it is released. I'm not sure if that's what you're saying in your question, you may have mixed kinematic and non-kinematic up?
If you have a non-kinematic rigid body with another non-kinematic rigid body parent without a physics constraint between them they can act very strangely.
I'll just mention as well, make sure you remove your object from the hierarchy of its parent when you detach it (set parent to null), otherwise you'll be dealing with the situation I describe above.
Answer by qobion · Oct 14, 2018 at 02:02 PM
You have 2 solutions
When you attach child, destroy Rigidbody component. When Detach add it again.
Add fixed joint to child and set parent as connected body
Your answer
Follow this Question
Related Questions
Problems with Physics(Flipping strangely) 2 Answers
Setting a RigidBody's velocity messes with my custom gravity, not sure how to proceed. 0 Answers
Moving rigidbody (Player) with addForce or Velocity ? 1 Answer
Rigidbody.velocity seems to be breaking jumping physics 0 Answers
VR Sword Physics, how to add force or velocity to the sword for impact when it hits an object 1 Answer