12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using System;
- using Sensors;
- using Sensors.Polar;
- using UnityEngine;
- namespace Controller.Lean
- {
-
- [Serializable]
- public struct PolarRotationMapping
- {
- public float maxRight;
- public float center;
- }
-
- public class PolarLeanController: ILeanController
- {
- public PolarSensorConfig polarSensorConfig;
- public PolarRotationMapping polarRotationMapping;
- private float leanFactor;
- private BikeSensorData sensorData;
- public float LeanAngle => leanAngle;
- private float leanAngle = 0f;
- private void Start()
- {
- sensorData = BikeSensorData.Instance;
- sensorData.StartListening(polarSensorConfig: polarSensorConfig);
- leanFactor = 90f / (polarRotationMapping.maxRight - polarRotationMapping.center);
- }
- private void Update()
- {
- var polarData = sensorData.PolarData;
- if (polarData != null)
- {
- leanAngle = (polarData.Value.Acc.y - polarRotationMapping.center) * leanFactor;
- }
- }
- }
- }
|