Let a tree fall over (to the left or right)

Hi,

I am trying to let a tree fall over (to the left or right) but with no luck.
My player controller is moving over a trigger and in this function “OnTriggerEnter” I want a specific tree (GameObject) to fall over. The tree has a proper collider and a RigidBody.

Does anybody have a short snippet, that shows how the tree can fall, i. e. to the left side?

Thanks!

Adding force to the tree is one way to do that via scripting. But I would go with the custom animation.

Hmm… I am not that good in animations thats why I chose to go for scripting :frowning:
I already added a force but the tree object does not do anything… see code below

using UnityEngine;
using System.Collections;

public class Falling : MonoBehaviour
{

    /**
     * Target object, that should fall over
     */
    public GameObject TargetObject;

    /**
     * Trigger, if player enters then the TargetObject should fall
     *
     * @param Collider other
     * @return void
     */
    public void OnTriggerEnter (Collider other)
    {
        Debug.Log ("Target Object: " + TargetObject.name);

        TargetObject.GetComponent<Rigidbody>().AddForce(Vector3.forward);
        TargetObject.transform.rotation = Quaternion.LookRotation( Vector3.forward, Vector3.up);

    }

    public void OnTriggerStay (Collider other)
    {
        Debug.Log ("Object is inside trigger");
    }

    public void OnTriggerExit (Collider other)
    {
        Debug.Log ("Object exits trigger");
    }


}

Sometimes, the force is too small to affect anything.

Even if I multiply the force by 100

TargetObject.GetComponent<Rigidbody>().AddForce(Vector3.forward * 100f);

nothing moves…
I really have no idea what to change in the code, so that the tree will fall :frowning:

I had nothing to do, so I made a video just for you :wink: …Here is the how to video:

2 Likes

WTF… superb :slight_smile: … I will check my scripts again, what that looks the same as mine.
Really thanks so far…I get back if I cannot figure it out

So, it turned out that I had “IsKinematic” checked, which blocks the tree from falling :slight_smile:
It now works as expected … thanks OneDragutin.

Solved!