Rotate Z or X Axis of tree Away from player.

I am trying to get a tree to fall, when tree is out of wood resource(random amount). At the moment i have the tree so it will very slowly, snail speed, sink into the ground. But at same time i want it to fall/rotate away from the player on the Z or X axis. I do not want the tree to fall on the player.

How can i achieve this?

Thanks in advance.

Let me explain it better(hopefully):
Say the player chops the tree from its south, the tree should fall to the north.Vice Versa: Player chops at trees west tree falls east. (Except -x, +x, -z, +z, instead of north, east,west and south)

Hope that explains a bit better! :slight_smile:


void Update () {
		if(resourceAvailable <= 0){
			objectDead = true;

			case Type.Tree:

			case Type.Rock:
			case Type.Animal:


    void TreeDead(){
    		Vector3 fallPos = transform.position;
    		fallPos.y -= treeSinkSpeed * Time.deltaTime;
    		transform.position = fallPos;
    		if(transform.rotation.x < 90){
    			Vector3 dir = transform.position - Player.position;
    			Vector3 axis = Vector3.Cross(dir, Vector3.up);
    			transform.rotation = Quaternion.AngleAxis(treeFallSpeed * Time.deltaTime, axis);

    //			Quaternion fallRotation = transform.rotation;
    //			fallRotation.x += treeFallSpeed * Time.deltaTime;
    //			transform.rotation = fallRotation;

There are a lot of unknowns here. If you are talking about the direct manipulation of the transform, you can solve it by using an angle/axis rotation. Vector3.Cross() can be used to calculate the axis. Something like:

var dir = transform.position - character.transform.position;
var axis = Vector3.Cross(dir, Vector3.up);

Then in update you can rotate your tree:

transform.rotation = Quaternion.AngleAxis(speed * Time.deltaTime, axis);

Note this will rotate the object around the pivot point. If this point is not at the base of the tree, you’ll have more work to do.