/// <summary> /// Called by Unity every frame. This method uses the sensor CanSee to change the color of the robot. /// It moves the robot linearly along the path defined by the waypoints /// /// Date Author Description /// 2017-11-02 BRB Initial Testing /// </summary> void Update() { myRenderer.material.color = sensor.CanSee(target)?Color.red:Color.green; // Use of sensor int back = Mathf.FloorToInt(u); int ahead = (back + 1) % wayPoint.Length; Vector3 delta = wayPoint[ahead] - transform.position; delta.Normalize(); Quaternion facing = Quaternion.LookRotation(delta); if (Vector3.Dot(delta, transform.forward) > CLOSE_ENOUGH_COSINE) { transform.rotation = facing; transform.position = Vector3.Lerp(wayPoint[back], wayPoint[ahead], u - back); u += SPEED * Time.deltaTime; if (u >= wayPoint.Length) { u -= wayPoint.Length; } } else { transform.rotation = Quaternion.RotateTowards(transform.rotation, facing, ANGLE + Time.deltaTime); } }
void Update() { //myRenderer.material.color = sensor.CanSee(target)?Color.red:Color.green; // Use of sensor foreach (Transform x in targets) { target = x; if (sensor.CanSee(target)) { Debug.Log("Found Target!"); tracker.Tracking(target); } } }