|
@@ -60,28 +60,30 @@ namespace Controller.Bicycle
|
|
private void FixedUpdate()
|
|
private void FixedUpdate()
|
|
{
|
|
{
|
|
ApplyVelocity();
|
|
ApplyVelocity();
|
|
|
|
+ ApplySteerAngleAndRotation();
|
|
}
|
|
}
|
|
|
|
|
|
private void ApplyVelocity()
|
|
private void ApplyVelocity()
|
|
{
|
|
{
|
|
- var targetVelocity = new Vector3(CalculateVelocityX(), 0, CurrentSpeed);
|
|
|
|
|
|
+ var targetVelocity = new Vector3(0, 0, CurrentSpeed);
|
|
targetVelocity = rbTransform.TransformDirection(targetVelocity);
|
|
targetVelocity = rbTransform.TransformDirection(targetVelocity);
|
|
var velocityChange = targetVelocity - rigidBody.velocity;
|
|
var velocityChange = targetVelocity - rigidBody.velocity;
|
|
velocityChange.y = 0;
|
|
velocityChange.y = 0;
|
|
rigidBody.AddForce(velocityChange, ForceMode.VelocityChange);
|
|
rigidBody.AddForce(velocityChange, ForceMode.VelocityChange);
|
|
}
|
|
}
|
|
|
|
|
|
- private float CalculateVelocityX()
|
|
|
|
- {
|
|
|
|
- var previousRotation = rbTransform.localRotation.eulerAngles;
|
|
|
|
- rbTransform.localRotation =
|
|
|
|
- Quaternion.Euler(previousRotation + new Vector3(0, CurrentSteerAngle, 0) * Time.fixedDeltaTime);
|
|
|
|
- return 0;
|
|
|
|
- //return CurrentSteerAngle/4; //TODO: something a bit smarter
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void ApplyLeaningAngle()
|
|
|
|
|
|
+ private void ApplySteerAngleAndRotation()
|
|
{
|
|
{
|
|
|
|
+ if (controllerMode == BicycleControllerMode.Independent)
|
|
|
|
+ {
|
|
|
|
+ var r = rbTransform.localRotation.eulerAngles;
|
|
|
|
+ rbTransform.localRotation = Quaternion.Euler(r + new Vector3(0, CurrentSteerAngle, -CurrentLeaningAngle) * Time.fixedDeltaTime);
|
|
|
|
+
|
|
|
|
+ }else if (controllerMode == BicycleControllerMode.LeaningAngleDependentOnSteerAngle)
|
|
|
|
+ {
|
|
|
|
+ //TODO
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|