IEnumerator AICycle() { while (true) { Debug.Log("tick"); this.distance = lidar.GetDistance(); var distanceDelta = distance - targetDistance; if (distanceDelta < -10) { distanceDelta = -10; } else if (distanceDelta > 10) { distanceDelta = 10; } distanceDelta += 10; distanceDelta = Mathf.Abs((float)distanceDelta); acceleration = fuzzyEngine.Defuzzify(new { Distance = distance, DistanceDelta = distanceDelta }) - 1; controller.accelleration = (float)acceleration; yield return(new WaitForSecondsRealtime(1)); } }
void UpdateText() { if (!lidar) { return; } var dist = lidar.GetDistance(); data.text = float.IsPositiveInfinity(dist) ? "INF" : dist + "m"; }
// Update is called once per frame void Update() { if (distanceFromLidar) { var lidarDistance = lidar.GetDistance(); controller.controllers[accelerationId].currentValue = float.IsPositiveInfinity(lidarDistance) ? 0 : lidarDistance; } else { controller.controllers[accelerationId].currentValue = myRigidbody.velocity.magnitude; } controller.controllers[steeringId].currentValue = transform.position.x; }