- Home /
Attaching Rigidbody breaks gravity
This question is specific I worry how much help I can get here, but.. just in case.
I've constructing a flying cargo ship. It grabs a cargo box.
The flying ship flies by applying constant upward force. Flies great, everything there is golden.
The cargo container has all the things you might expect, a rigid body, mass, etc.
I attach the cargo container at a certain point using:
MyContainer.rigidbody.isKinematic = true;
MyContainer.transform.parent=MyShip.transform;
That works fine too, everything attaches, the ship flies around with the container.
The trouble is that somehow the ship no longer falls to the ground when the engines are turned off (almost as if gravity is completely removed). My suspicion is that the isKinematic setting of the container is messing up the physics of the ship somehow.
If I do not apply isKinematic=true, then the cargo container does not attach at all.. which is strange considering that it becomes parented to the ship.
Again, I know this is specific and I'm not hiring you on, but I thank you even for reading this.
Yes, both have rigid bodies.
It flies using..
rigidbody.AddRelativeForce( Vector3.up * (gravityForce * enginePower) );
gravityForce is a calculation on the amount of force needed to hover without ascending or descending. enginePower varies from 0 to 2.
However, in my tests of this problem I completely kill the engines, which halts the application of the upward force (which I've verified). It should drop like a rock, but it just suspends in the air. When no container is attached it behaves as expected and plummets.
useGravity is set to true for both the ship and the container and is never affected. rigidbody.is$$anonymous$$inematic is TRUE when grabbed, but is set to FALSE when released. (I think I had it backwards in my code sample above, but changed it)
Also, releasing the container executes the following code.
$$anonymous$$yContainer.is$$anonymous$$inematic=false;
$$anonymous$$yContainer.transform.parent=null;
When executed the container will fall, as expected, and the unexpected physics effects on the ship cease.
Ok, I have a suspicion .. I think the grab action may cause 2 colliders to intersect, resulting in strange physics calculations. I am testing now.
If I am wrong I will test your statement about is$$anonymous$$inematic. I've also tested in that direction as well but I will verify again as to not waste your time. In previous tests, is$$anonymous$$inematic=true is required or the box will be parented but will not move with its parent. But, yes, more testing.. thanks for your input.
Answer by Fattie · Sep 10, 2012 at 07:52 AM
you're right, it is very confusing, and as is often discussed on this list ...
the specific combinations of what happens when one mixes different types of bodies, is sadly poorly or not documented in the Unity docs.
Just FTR my take ..
in this situation never use iKinematic at all
the Box should have a rigidbody
possibly turn off gravity on the box when it comes a bord
likely disable the colliders on the box when it comes a bord
possibly set the Box mass to zero (well, low) when it comes a bord
Perhaps no use at all but my take !
I will continue my tests on is$$anonymous$$inematic, and you clearly know more about this than I do.. but I'm thinking thats not the issue. Still, your answer hits the mark.. my problem is likely caused by the "clamps" squeezing the box to tightly and causing some physics weirdness. I greatly appreciate your help.
I know nothing! we're all just shooting in the dark - it's so difficult. The huge problem is there are $$anonymous$$ANY $$anonymous$$ANY WAYS to achieve these effects. For example, you could "really" make a small "room" (of colliders) inside your craft, and the box would "really" bounce around in there. Imagine that! That's the "ultimate simulation" method! It sounds like in a way you were TRYING TO DO THAT, but, with touching clamps. touching-pressure basically never works in physics engines, you have to fake it somehow ... exactly what led you to is$$anonymous$$inematic I bet. but that's not right, because is$$anonymous$$inematic essentially does not work at all in any joined situation with the physics engine (of course -- there are many exceptions to this!)
BTW have you considered trying t hinge or other JOINT ? sometimes that is another part of the mix !!!!!!!!!! sorry i could not help more decisively.
don;t forget in a way the cheapest and easiest solution is just make the box have "nothing" - no rigidbody, nothing whatsoever - it's just an image! and stick that on the aircraft ... that's the "cheap, go have lunch" solution! HEH!
Your answer
Follow this Question
Related Questions
Physics gravity appears very weak 2 Answers
How to make a object jump constantly at y and move to the next position to z (perfectly) 0 Answers
How can I turn on/off Rigidbody.useGravity? 0 Answers
Parenting Rigidbodies to Rigidbodies (Newtonian Space) 0 Answers
How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers