Minor - V0.3.0 - Ajoute frein classique et frein à main - V

Adds a traditional brake alongside the existing handbrake functionality.

This change allows for more controlled deceleration using a standard braking system and introduces a brake power parameter in the vehicle controller for further adjustment. The input manager is updated to accommodate a new brake input, and the vehicle controller uses this input to apply a progressive braking force, particularly at lower speeds.

Also corrects a typo in the braking logic.
This commit is contained in:
2026-02-03 19:27:33 +01:00
parent 7a3d9e54c4
commit 8ffb00a024
5 changed files with 162 additions and 34 deletions

View File

@@ -11,7 +11,10 @@ namespace ArcadeVP
public MovementMode movementMode;
public groundCheck GroundCheck;
public LayerMask drivableSurface;
[Range(0f, 1f)]
[Tooltip("Force du freinage classique (0 = aucun effet, 1 = arrêt immédiat)")]
public float brakePower = 0.3f;
public float MaxSpeed, accelaration, turn, gravity = 7f, downforce = 5f;
[Tooltip("if true : can turn vehicle in air")]
public bool AirControl = false;
@@ -48,7 +51,7 @@ namespace ArcadeVP
public float skidWidth;
private float radius, steeringInput, accelerationInput, brakeInput;
private float radius, steeringInput, accelerationInput, handbrakeInput, brakeInput;
private Vector3 origin;
private void Start()
@@ -66,10 +69,11 @@ namespace ArcadeVP
AudioManager();
}
public void ProvideInputs(float _steeringInput, float _accelarationInput, float _brakeInput)
public void ProvideInputs(float _steeringInput, float _accelarationInput, float _handbrakeInput, float _brakeInput)
{
steeringInput = _steeringInput;
accelerationInput = _accelarationInput;
handbrakeInput = _handbrakeInput;
brakeInput = _brakeInput;
}
@@ -103,7 +107,7 @@ namespace ArcadeVP
//turnlogic
float sign = Mathf.Sign(carVelocity.z);
float TurnMultiplyer = turnCurve.Evaluate(carVelocity.magnitude / MaxSpeed);
if (kartLike && brakeInput > 0.1f) { TurnMultiplyer *= driftMultiplier; } //turn more if drifting
if (kartLike && handbrakeInput > 0.1f) { TurnMultiplyer *= driftMultiplier; } //turn more if drifting
if (accelerationInput > 0.1f || carVelocity.z > 1)
@@ -117,10 +121,10 @@ namespace ArcadeVP
// mormal brakelogic
// mormal handbrakelogic
if (!kartLike)
{
if (brakeInput > 0.1f)
if (handbrakeInput > 0.1f)
{
rb.constraints = RigidbodyConstraints.FreezeRotationX;
}
@@ -134,27 +138,36 @@ namespace ArcadeVP
if (movementMode == MovementMode.AngularVelocity)
{
if (Mathf.Abs(accelerationInput) > 0.1f && brakeInput < 0.1f && !kartLike)
{
rb.angularVelocity = Vector3.Lerp(rb.angularVelocity, carBody.transform.right * accelerationInput * MaxSpeed / radius, accelaration * Time.deltaTime);
}
else if (Mathf.Abs(accelerationInput) > 0.1f && kartLike)
{
rb.angularVelocity = Vector3.Lerp(rb.angularVelocity, carBody.transform.right * accelerationInput * MaxSpeed / radius, accelaration * Time.deltaTime);
}
HandleAngularAcceleration();
}
else if (movementMode == MovementMode.Velocity)
{
if (Mathf.Abs(accelerationInput) > 0.1f && brakeInput < 0.1f && !kartLike)
{
rb.linearVelocity = Vector3.Lerp(rb.linearVelocity, carBody.transform.forward * accelerationInput * MaxSpeed, accelaration / 10 * Time.deltaTime);
}
else if (Mathf.Abs(accelerationInput) > 0.1f && kartLike)
{
rb.linearVelocity = Vector3.Lerp(rb.linearVelocity, carBody.transform.forward * accelerationInput * MaxSpeed, accelaration / 10 * Time.deltaTime);
}
HandleLinearAcceleration();
}
// if (movementMode == MovementMode.AngularVelocity)
// {
// if (Mathf.Abs(accelerationInput) > 0.1f && handbrakeInput < 0.1f && !kartLike)
// {
// rb.angularVelocity = Vector3.Lerp(rb.angularVelocity, carBody.transform.right * accelerationInput * MaxSpeed / radius, accelaration * Time.deltaTime);
// }
// else if (Mathf.Abs(accelerationInput) > 0.1f && kartLike)
// {
// rb.angularVelocity = Vector3.Lerp(rb.angularVelocity, carBody.transform.right * accelerationInput * MaxSpeed / radius, accelaration * Time.deltaTime);
// }
// }
// else if (movementMode == MovementMode.Velocity)
// {
// if (Mathf.Abs(accelerationInput) > 0.1f && handbrakeInput < 0.1f && !kartLike)
// {
// rb.linearVelocity = Vector3.Lerp(rb.linearVelocity, carBody.transform.forward * accelerationInput * MaxSpeed, accelaration / 10 * Time.deltaTime);
// }
// else if (Mathf.Abs(accelerationInput) > 0.1f && kartLike)
// {
// rb.linearVelocity = Vector3.Lerp(rb.linearVelocity, carBody.transform.forward * accelerationInput * MaxSpeed, accelaration / 10 * Time.deltaTime);
// }
// }
// down froce
rb.AddForce(-transform.up * downforce * rb.mass);
@@ -176,6 +189,61 @@ namespace ArcadeVP
}
}
private void HandleAngularAcceleration()
{
if (brakeInput > 0.1f)
{
rb.angularVelocity *= (1f - brakeInput * 0.3f);
return;
}
if (Mathf.Abs(accelerationInput) > 0.1f && handbrakeInput < 0.1 && !kartLike)
{
rb.angularVelocity = Vector3.Lerp(rb.angularVelocity,
carBody.transform.right * accelerationInput * MaxSpeed / radius,
accelaration * Time.deltaTime);
}
else if (Mathf.Abs(accelerationInput) > 0.1f && kartLike)
{
rb.angularVelocity = Vector3.Lerp(rb.angularVelocity,
carBody.transform.right * accelerationInput * MaxSpeed / radius,
accelaration * Time.deltaTime);
}
}
private void HandleLinearAcceleration()
{
// Frein classique : réduit progressivement avec courbe d'amortissement
if (brakeInput > 0.1f)
{
// Frein exponentiel : plus on enfonce, plus c'est agressif
float brakeFactor = 1f - Mathf.Pow(brakeInput, 1.5f) * brakePower;
rb.linearVelocity *= brakeFactor;
// Arrêt complet en dessous d'une certaine vitesse
if (rb.linearVelocity.magnitude < 0.5f)
{
rb.linearVelocity = Vector3.zero;
}
return;
}
// Accélération normale (sans frein)
if (Mathf.Abs(accelerationInput) > 0.1f && handbrakeInput < 0.1f && !kartLike)
{
rb.linearVelocity = Vector3.Lerp(rb.linearVelocity,
carBody.transform.forward * accelerationInput * MaxSpeed,
accelaration / 10 * Time.deltaTime);
}
else if (Mathf.Abs(accelerationInput) > 0.1f && kartLike)
{
rb.linearVelocity = Vector3.Lerp(rb.linearVelocity,
carBody.transform.forward * accelerationInput * MaxSpeed,
accelaration / 10 * Time.deltaTime);
}
}
public void Visuals()
{
//tires
@@ -202,7 +270,7 @@ namespace ArcadeVP
if (kartLike)
{
if (brakeInput > 0.1f)
if (handbrakeInput > 0.1f)
{
BodyMesh.parent.localRotation = Quaternion.Slerp(BodyMesh.parent.localRotation,
Quaternion.Euler(0, 45 * steeringInput * Mathf.Sign(carVelocity.z), 0),