Hi all,
I am trying to get an object to follow another as it randomly moves position.
The problem is that the target (a cube) just blinks from position to position like it should, and the drone(a sphere) copies that behaviour, rather than actually travelling towards the target.
i am using moveTowards method for this.
here is the code, really appreciate any input on this one.
Thanks in advance
public float positionX = 0f;
public float positionY = 0f;
public float positionZ = 0f;
private float speed = 1f; // move speed
public float delayTime = 0f;
public float executeTime = 0f;
private GameObject move_cube;
private Vector3 wayPointPos;
private GameObject drone;
// Use this for initialization
void Start () {
executeTime = Random.Range (0f, 4f);
move_cube = GameObject.Find("move_cube");
drone = GameObject.Find ("drone");
}
void Update () {
delayTime += Time.deltaTime;
if (delayTime >= executeTime) {
executeTime = Random.Range (0f, 4f);
delayTime = 0f;
positionX = Random.Range (0f, 5f);
positionY = Random.Range (0f, 5f);
positionZ = Random.Range (0f, 5f);
}
move_cube.transform.position = new Vector3 (positionX, positionY, positionZ);
wayPointPos = new Vector3 (move_cube.transform.position.x, move_cube.transform.position.y, move_cube.transform.position.z);
drone.transform.position = Vector3.MoveTowards(transform.position, wayPointPos, 1f * Time.deltaTime);