Browse Source

Make Steering selectable by dropdown

Till Steinert 2 years ago
parent
commit
b4b3a77f7a
2 changed files with 25 additions and 4 deletions
  1. BIN
      Assets/Scenes/MainScene.unity
  2. 25 4
      Assets/Scripts/Controller/SensorBikeController.cs

BIN
Assets/Scenes/MainScene.unity


+ 25 - 4
Assets/Scripts/Controller/SensorBikeController.cs

@@ -20,22 +20,28 @@ namespace Controller
     [RequireComponent(typeof(IBicycleController))]
     public class SensorBikeController : MonoBehaviour
     {
+        public enum SteeringMode { frontWheel, Leaning, HMD };
         public PolarRotationMapping polarRotationMapping;
         public FrontWheelTrackerConfig frontWheelTrackerConfig;
 
         public bool steer = true;
         public bool accelerate = true;
         public bool lean = true;
+        public SteeringMode steeringSelection;
 
         private IBicycleController bicycleController;
         private bool isFrontWheelTrackerNotNull;
         private BikeSensorData sensorData;
+        private GameObject player;
 
         private void Start()
         {
             isFrontWheelTrackerNotNull = frontWheelTrackerConfig.frontWheelTracker != null;
             bicycleController = GetComponent<IBicycleController>();
             sensorData = BikeSensorData.Instance;
+            player = GameObject.FindGameObjectWithTag("HMDTracker");
+            // Dummy assignment
+            steeringSelection = SteeringMode.HMD;
         }
 
         private void Update()
@@ -44,15 +50,30 @@ namespace Controller
 
             if (speedData != null && accelerate) SetSpeed(speedData.Value);
 
-            if (isFrontWheelTrackerNotNull && steer) SetSteer();
+            if (steer) SetSteer();
 
             if (lean) SetLeaningAngle();
         }
 
         private void SetSteer()
         {
-            bicycleController.CurrentSteerAngle =
-                frontWheelTrackerConfig.AdjustedRotation;
+            Debug.Log("Updating Steering");
+            switch (steeringSelection) {
+                case SteeringMode.frontWheel:
+                    if (isFrontWheelTrackerNotNull) {
+                        bicycleController.CurrentSteerAngle = frontWheelTrackerConfig.AdjustedRotation;
+                    }
+                    break;
+                case SteeringMode.Leaning:
+                    // TBD
+                    bicycleController.CurrentSteerAngle = 0;
+                    break;
+                case SteeringMode.HMD: 
+                    // TODO: Convert steering relative to bike
+                    bicycleController.CurrentSteerAngle = player.transform.rotation.y;
+                    Debug.Log("Updating Steering Angle to " + bicycleController.CurrentSteerAngle);
+                    break;
+            }
         }
 
         private void SetLeaningAngle()
@@ -65,4 +86,4 @@ namespace Controller
             bicycleController.CurrentSpeed = speedData.Speed;
         }
     }
-}
+}