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:
@@ -8,7 +8,7 @@ PhysicsMaterial:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Friction
|
||||
serializedVersion: 2
|
||||
m_DynamicFriction: 1.000001
|
||||
m_DynamicFriction: 1
|
||||
m_StaticFriction: 1
|
||||
m_Bounciness: 0
|
||||
m_FrictionCombine: 3
|
||||
|
||||
@@ -12,6 +12,9 @@ namespace ArcadeVP
|
||||
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),
|
||||
|
||||
@@ -7,15 +7,18 @@ namespace ArcadeVP
|
||||
{
|
||||
public ArcadeVehicleController arcadeVehicleController;
|
||||
|
||||
[HideInInspector] public float horizontal;
|
||||
[HideInInspector] public float vertical;
|
||||
[HideInInspector] public float jump;
|
||||
[HideInInspector] public float steering;
|
||||
[HideInInspector] public float acceleration;
|
||||
[HideInInspector] public float handbrake;
|
||||
[HideInInspector] public float brake;
|
||||
|
||||
private PlayerInput _playerInput;
|
||||
private InputAction _steerAction;
|
||||
private InputAction _accelAction;
|
||||
private InputAction _handbrakeAction;
|
||||
private InputAction _brakeAction;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_playerInput = GetComponent<PlayerInput>();
|
||||
@@ -27,16 +30,18 @@ namespace ArcadeVP
|
||||
|
||||
_steerAction = _playerInput.actions["Steer"];
|
||||
_accelAction = _playerInput.actions["Accelerate"];
|
||||
_brakeAction = _playerInput.actions["HandBrake"];
|
||||
_handbrakeAction = _playerInput.actions["HandBrake"];
|
||||
_brakeAction = _playerInput.actions["Brake"];
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
horizontal = _steerAction?.ReadValue<float>() ?? 0f;
|
||||
vertical = _accelAction?.ReadValue<float>() ?? 0f;
|
||||
jump = _brakeAction?.ReadValue<float>() ?? 0f;
|
||||
steering = _steerAction?.ReadValue<float>() ?? 0f;
|
||||
acceleration = _accelAction?.ReadValue<float>() ?? 0f;
|
||||
handbrake = _handbrakeAction?.ReadValue<float>() ?? 0f;
|
||||
brake = _brakeAction?.ReadValue<float>() ?? 0f;
|
||||
|
||||
arcadeVehicleController.ProvideInputs(horizontal, vertical, jump);
|
||||
arcadeVehicleController.ProvideInputs(steering, acceleration, handbrake, brake);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,15 @@
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Brake",
|
||||
"type": "Button",
|
||||
"id": "1017a834-ab02-4e41-9787-39fd6ca9c6ad",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
@@ -122,6 +131,28 @@
|
||||
"action": "Accelerate",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "a7488085-5421-409b-bd61-cc6fda5e2dec",
|
||||
"path": "<Gamepad>/leftTrigger",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Brake",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "1dffb4da-1be5-49ca-9344-288d594e6a94",
|
||||
"path": "<Keyboard>/s",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Brake",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -315,8 +315,8 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 330585543}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0.27704412, y: 0, z: 0, w: 0.9608572}
|
||||
m_LocalPosition: {x: 1.9644628, y: 7.0570297, z: -4.107703}
|
||||
m_LocalRotation: {x: 0.2181528, y: 0, z: 0, w: 0.97591466}
|
||||
m_LocalPosition: {x: 1.9644628, y: 6.2770295, z: -5.0077033}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@@ -949,6 +949,30 @@ PrefabInstance:
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3647447231556822330, guid: f80147e53b6c59543b384359e9759152, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 4
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3647447231556822330, guid: f80147e53b6c59543b384359e9759152, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: -8.5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3647447231556822330, guid: f80147e53b6c59543b384359e9759152, type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 0.97591466
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3647447231556822330, guid: f80147e53b6c59543b384359e9759152, type: 3}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: 0.2181528
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4888852074431289531, guid: f80147e53b6c59543b384359e9759152, type: 3}
|
||||
propertyPath: FollowOffset.y
|
||||
value: 4
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4888852074431289531, guid: f80147e53b6c59543b384359e9759152, type: 3}
|
||||
propertyPath: FollowOffset.z
|
||||
value: -8.5
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
|
||||
Reference in New Issue
Block a user