|
@@ -1,15 +1,12 @@
|
|
|
-using System;
|
|
|
-using System.Collections;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Linq;
|
|
|
+using System.Collections.Generic;
|
|
|
+using Controller.Bicycle;
|
|
|
using UnityEngine;
|
|
|
-using UnityEngine.EventSystems;
|
|
|
using UnityEngine.Serialization;
|
|
|
using Valve.VR.InteractionSystem;
|
|
|
|
|
|
-namespace Controller
|
|
|
+namespace Controller.Bicycle
|
|
|
{
|
|
|
- public class BicycleController : MonoBehaviour
|
|
|
+ public class WcBicycleController : MonoBehaviour, IBicycleController
|
|
|
{
|
|
|
#region Variables
|
|
|
|
|
@@ -23,25 +20,24 @@ namespace Controller
|
|
|
[Header("Values")] public float offsetCollidersFromWheel = 0.25f;
|
|
|
public float maxLeaningAngle = 35f;
|
|
|
public float maxSteeringAngle = 80f;
|
|
|
- public float maxMotorTorque = 2000f;
|
|
|
+ [Range(0,15)]
|
|
|
+ [Tooltip("Speed in m/s")]
|
|
|
+ public float maxSpeed = 11.111f;
|
|
|
public float maxBreakTorque = 2000f;
|
|
|
+ public float maxMotorTorque = 1000f;
|
|
|
|
|
|
- public float CurrentSteerAngle
|
|
|
- {
|
|
|
- get => currentSteerAngle;
|
|
|
- set => currentSteerAngle = Mathf.Clamp(value, -maxSteeringAngle, maxSteeringAngle);
|
|
|
- }
|
|
|
+ public BicycleControllerMode ControllerMode { get; set; }
|
|
|
|
|
|
- public float CurrentMotorTorque
|
|
|
+ public float CurrentSpeed
|
|
|
{
|
|
|
- get => currentMotorTorque;
|
|
|
- set => currentMotorTorque = Mathf.Clamp(value, -maxMotorTorque, maxMotorTorque);
|
|
|
+ get => currentSpeed;
|
|
|
+ set => currentSpeed = Mathf.Clamp(value, 0, maxSpeed);
|
|
|
}
|
|
|
|
|
|
- public float CurrentBrakeTorque
|
|
|
+ public float CurrentSteerAngle
|
|
|
{
|
|
|
- get => currentBrakeTorque;
|
|
|
- set => currentBrakeTorque = Mathf.Clamp(value, -maxBreakTorque, maxBreakTorque);
|
|
|
+ get => currentSteerAngle;
|
|
|
+ set => currentSteerAngle = Mathf.Clamp(value, -maxSteeringAngle, maxSteeringAngle);
|
|
|
}
|
|
|
|
|
|
public float CurrentLeaningAngle
|
|
@@ -53,9 +49,8 @@ namespace Controller
|
|
|
private WheelCollider[] allWheelColliders;
|
|
|
private float initialWheelColliderY;
|
|
|
private float currentSteerAngle = 0f;
|
|
|
- private float currentMotorTorque = 0f;
|
|
|
- private float currentBrakeTorque = 0f;
|
|
|
private float currentLeaningAngle = 0f;
|
|
|
+ private float currentSpeed;
|
|
|
|
|
|
#endregion
|
|
|
|
|
@@ -94,10 +89,33 @@ namespace Controller
|
|
|
|
|
|
private void ControlTorque(IEnumerable<WheelCollider> colliders)
|
|
|
{
|
|
|
+ var rbSpeed = rigidBody.velocity.magnitude;
|
|
|
+ var speedDif = CurrentSpeed - rbSpeed;
|
|
|
+ var ratio = speedDif / maxSpeed;
|
|
|
+
|
|
|
+
|
|
|
+ var brakeTorque = 0f;
|
|
|
+ var motorTorque = 0f;
|
|
|
+
|
|
|
+ if (speedDif >= .1f)
|
|
|
+ {
|
|
|
+ var torque = maxMotorTorque * ratio;
|
|
|
+
|
|
|
+ brakeTorque = 0;
|
|
|
+ motorTorque = torque;
|
|
|
+ }
|
|
|
+ else if (speedDif <= -.1f)
|
|
|
+ {
|
|
|
+ var torque = -maxBreakTorque * ratio;
|
|
|
+
|
|
|
+ motorTorque = 0;
|
|
|
+ brakeTorque = torque;
|
|
|
+ }
|
|
|
+
|
|
|
foreach (var c in colliders)
|
|
|
{
|
|
|
- c.motorTorque = CurrentMotorTorque;
|
|
|
- c.brakeTorque = CurrentBrakeTorque;
|
|
|
+ c.motorTorque = motorTorque;
|
|
|
+ c.brakeTorque = brakeTorque;
|
|
|
}
|
|
|
}
|
|
|
|