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 PolarRotationMapping polarRotationMapping; private float leanFactor; private BikeSensorData sensorData; public float LeanAngle => leanAngle; private float leanAngle = 0f; private void Start() { sensorData = BikeSensorData.Instance; leanFactor = 90f / (polarRotationMapping.maxRight - polarRotationMapping.center); } private void Update() { var polarData = sensorData.PolarData; if (polarData != null) { leanAngle = (polarData.Value.Acc.y - polarRotationMapping.center) * leanFactor; } } } }