//========================================== private void CarControlUpdate() { // Use the device's roll to compute the steering angle of the (front) wheels. float deviceRoll = GyroAccel.GetRoll(); float steering = controlSettings.steeringVsRollCurve.Evaluate(-deviceRoll); // Get acceleration and braking from the VirtualButtons float accel = 0f; if (controlSettings.acceleratorButtonName == "" || controlSettings.acceleratorButtonName == "") { ErrorHandling.LogError("Warning [CarUSerControl]: " + "please specify the correct name of the VirtualButtons used for accelerating and/or braking."); } else { if (VirtualButton.GetButton(controlSettings.brakeButtonName)) { accel -=1f; } if (VirtualButton.GetButton(controlSettings.acceleratorButtonName)) { accel +=1f; } } // Send the steering and accel values to the carController controlSettings.carController.Move(steering, accel, accel, 0f); } // private void CarControlUpdate()
} // private void CarControlUpdate() //========================================== private void CameraPositionAndRotationUpdate() { // the camera heading will align with the car's heading Vector3 carDirection = transform.forward; Vector3 carFlatDirection = new Vector3(carDirection.x, 0f, carDirection.z); if (carFlatDirection.sqrMagnitude > 0f) { float carCurrentHeading = Vector3.Angle(Vector3.forward,carFlatDirection) * Mathf.Sign(carFlatDirection.x); float smoothFactor = 1f; if (cameraSettings.smoothingTime > Time.deltaTime) { smoothFactor = Time.deltaTime / cameraSettings.smoothingTime; } carHeading = Mathf.LerpAngle(carHeading,carCurrentHeading,smoothFactor); } // Set the camera rotation float camHeading = carHeading; float camPitch = GyroAccel.GetPitch(); float camRoll = GyroAccel.GetRoll(); cameraSettings.playerCamera.rotation = GyroAccel.GetQuaternionFromHeadingPitchRoll(camHeading,camPitch,camRoll); // Set the camera position cameraSettings.playerCamera.position = transform.position + cameraSettings.cameraOffset - cameraSettings.cameraDistanceVsPitchCurve.Evaluate(camPitch)*cameraSettings.playerCamera.forward; } // private void CameraPositionAndRotationUpdate()