hi there this is my first time trying this,I want to have a tree that is choppable and my problem is that my script bellow doesn't add force correctly here's the code :
using UnityEngine;
using System.Collections;
public class felltree : MonoBehaviour
{
public int Treehealth;
public GameObject Treeprefab;
public GameObject Treestump;
public GameObject Treetrunk;
public Transform holder;
// Use this for initialization
void Start ()
{
Treehealth = 6;
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown ("space")) {
Treehealth -= 2;
if (Treehealth <= 0) {
Treehealth = 0;
Felltree ();
Debug.Log ("felling tree");
}
}
}
void Felltree ()
{
Instantiate (Treestump, Treeprefab.transform.position + new Vector3 (0.1f, 0, 0), Treeprefab.transform.rotation);
Instantiate (Treetrunk, Treestump.transform.position, Treeprefab.transform.rotation);
Destroy (Treeprefab);
Treetrunk.GetComponent ().isKinematic = false;
Treetrunk.GetComponent ().AddForceAtPosition (new Vector3 (200f, 0, 0),new Vector3(0,1f,0));
Debug.Log ("adding force to tree");
}
}
how this is supposed to work is I have a full tree ,a stump and a tree trunk that I made in blender, the script replaces the full tree with the stump and trunk objects and adds force to the trunk to make it fall over so that eventually it can be processed by a settler, I'm obviously doing something(if not everything) wrong,
here's a screenshot of the hierarchy showing the script attached to the tree
http://imageshack.com/a/img673/937/3xFcHW.png
heres one of the script in action
http://imageshack.com/a/img538/9983/bAtpl3.png
and here is the console during the last image
http://imageshack.com/a/img661/8564/bp64ID.png
thank you in advance for your help
↧