Disable Rigidbody Gravity until collision
I want to add props to a scene and I want them to be static until something collides with one of their colliders. I thought it would make sense to have Rigidbody.useGravity set to false until the collider on the object triggered and I then set useGravity to true. The point was to not have a lot of props with physics properties until they needed to move. I thought it would also help with things like lamp posts that would fall over if not anchored. However, my script simply turns on gravity and the object falls without colliding with the ground. When gravity is on at the start, the object does not fall through the ground.
What am I doing wrong? Is there a better approach?
Answer by RogerGu · Jan 11, 2016 at 10:40 PM
Ah Ha! >> http://answers.unity3d.com/questions/30677/how-can-i-make-my-physics-objects-stay-frozen-eg-i.html
myRigidBody.Sleep();
Answer by MastersOfUs · Jan 11, 2016 at 07:32 PM
You have to add a collider component to both the ground and the prop.
They both have a collider (the prop and the ground), and they collide as desired when Use Gravity is checked for the rigidbody of the prop at the start of the scene.
What is not working:
I checked 'Is Trigger' on the Box collider of the prop game object
I uncheck 'use Gravity' on the rigidbody.
I have a script attached to the prop game object that simply turns on the gravity for the rigidbody of the prop
Ins$$anonymous$$d of colliding and resting on the ground, the pop falls through the collider for the ground.
Your answer
Follow this Question
Related Questions
ontriggerexit not working 0 Answers
ECS performent collision 0 Answers
OnTriggerExit not working 0 Answers
Fast moving 2D objects workarounds and performance tradeoffs? 1 Answer
Object falling from high are passing through ground 2 Answers