- Home /
Trees are flying when rigidbody is activated
(Here is a video) https://streamable.com/xdzu6
I'm trying to make a tree fall when it's health is 0. I then add rigidbody and use AddForce to make it fall, but it flies instead. I also tried setting it's mass and drag to some crazy high number with no success.
My Code:
private void Update()
{
if(Health <= 0 && !chopped)
{
Rigidbody _rb = this.gameObject.AddComponent<Rigidbody>();
_rb.mass = 100;
_rb.drag = 1000000;
_rb.useGravity = true;
_rb.AddForce(Vector3.forward, ForceMode.Impulse);
_rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;
chopped = true;
}
if(chopped)
{
StartCoroutine(RemoveFromScene());
}
}
If anyone has any idea what could be wrong please tell me, it's been driving me crazy.
Thanks.
It's because the pivot point of the collider (used for rotation) is in the center of the collider. Try offsetting it so it rotates around the bottom (I'm assu$$anonymous$$g it's behavior you want).
Hey, thanks, I don't really know what a pivot point of a collider is, but I've tried to lower the collider, so it's more at the bottom. Now it's beahving even weirder.
(Video of that) https://streamable.com/tibxs
Answer by itsharshdeep · Oct 06, 2018 at 04:10 PM
Hi @vakkeh,
Kindly check the following script and video, this might help you out:
Script: https://pastebin.com/6N7j3qe2
Video: https://www.dropbox.com/s/oh1k26heotfk5lg/TreeFalling.mov?dl=0
I believe you need to :
Remove the constraint
Add collider to ground
Add force towards the required direction
The pivot should be correct
Hope that will help you out.
Your answer
Follow this Question
Related Questions
Rocket-styled angular drag 0 Answers
Fly Mode 2D + Rigid Body vs CharacterController problems 0 Answers
Rigidbody + Character Controller = flight? 1 Answer
Gently Restricting Helicopter Rigidbody Movement 0 Answers
Enemy floating problem 1 Answer