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.
EDIT
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!
CODE:
void Update () {
if(resourceAvailable <= 0){
objectDead = true;
switch(ObjectType){
case Type.Tree:
TreeDead();
break;
case Type.Rock:
break;
case Type.Animal:
break;
default:
break;
}
}
}
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;
}
}