1
0

PolarLeanController.cs 974 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using Sensors;
  3. using Sensors.Polar;
  4. using UnityEngine;
  5. namespace Controller.Lean
  6. {
  7. [Serializable]
  8. public struct PolarRotationMapping
  9. {
  10. public float maxRight;
  11. public float center;
  12. }
  13. public class PolarLeanController : ILeanController
  14. {
  15. public PolarRotationMapping polarRotationMapping;
  16. private float leanFactor;
  17. private BikeSensorData sensorData;
  18. public float LeanAngle => leanAngle;
  19. private float leanAngle = 0f;
  20. private void Start()
  21. {
  22. sensorData = BikeSensorData.Instance;
  23. leanFactor = 90f / (polarRotationMapping.maxRight - polarRotationMapping.center);
  24. }
  25. private void Update()
  26. {
  27. var polarData = sensorData.PolarData;
  28. if (polarData != null)
  29. {
  30. leanAngle = (polarData.Value.Acc.y - polarRotationMapping.center) * leanFactor;
  31. }
  32. }
  33. }
  34. }