From 8ffb00a024addc3cc27abfbff5f07068e8dd1f0f Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Tue, 3 Feb 2026 19:27:33 +0100 Subject: [PATCH] =?UTF-8?q?Minor=20-=20V0.3.0=20-=20Ajoute=20frein=20class?= =?UTF-8?q?ique=20et=20frein=20=C3=A0=20main=20-=20V?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../Materials/Friction.physicMaterial | 2 +- .../Scripts/ArcadeVehicleController.cs | 114 ++++++++++++++---- .../Scripts/InputManager_ArcadeVP.cs | 21 ++-- Assets/Input/AE86-3DS_IA.inputactions | 31 +++++ Assets/Scenes/MainMap.unity | 28 ++++- 5 files changed, 162 insertions(+), 34 deletions(-) diff --git a/Assets/Ash Assets/Arcade Vehicle Physics/Materials/Friction.physicMaterial b/Assets/Ash Assets/Arcade Vehicle Physics/Materials/Friction.physicMaterial index 7cbebb3..5d35b9c 100644 --- a/Assets/Ash Assets/Arcade Vehicle Physics/Materials/Friction.physicMaterial +++ b/Assets/Ash Assets/Arcade Vehicle Physics/Materials/Friction.physicMaterial @@ -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 diff --git a/Assets/Ash Assets/Arcade Vehicle Physics/Scripts/ArcadeVehicleController.cs b/Assets/Ash Assets/Arcade Vehicle Physics/Scripts/ArcadeVehicleController.cs index a92bea4..5e1796c 100644 --- a/Assets/Ash Assets/Arcade Vehicle Physics/Scripts/ArcadeVehicleController.cs +++ b/Assets/Ash Assets/Arcade Vehicle Physics/Scripts/ArcadeVehicleController.cs @@ -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), diff --git a/Assets/Ash Assets/Arcade Vehicle Physics/Scripts/InputManager_ArcadeVP.cs b/Assets/Ash Assets/Arcade Vehicle Physics/Scripts/InputManager_ArcadeVP.cs index f443ace..f2f71c1 100644 --- a/Assets/Ash Assets/Arcade Vehicle Physics/Scripts/InputManager_ArcadeVP.cs +++ b/Assets/Ash Assets/Arcade Vehicle Physics/Scripts/InputManager_ArcadeVP.cs @@ -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(); @@ -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() ?? 0f; - vertical = _accelAction?.ReadValue() ?? 0f; - jump = _brakeAction?.ReadValue() ?? 0f; + steering = _steerAction?.ReadValue() ?? 0f; + acceleration = _accelAction?.ReadValue() ?? 0f; + handbrake = _handbrakeAction?.ReadValue() ?? 0f; + brake = _brakeAction?.ReadValue() ?? 0f; - arcadeVehicleController.ProvideInputs(horizontal, vertical, jump); + arcadeVehicleController.ProvideInputs(steering, acceleration, handbrake, brake); } } } diff --git a/Assets/Input/AE86-3DS_IA.inputactions b/Assets/Input/AE86-3DS_IA.inputactions index a1515ab..032a6e9 100644 --- a/Assets/Input/AE86-3DS_IA.inputactions +++ b/Assets/Input/AE86-3DS_IA.inputactions @@ -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": "/leftTrigger", + "interactions": "", + "processors": "", + "groups": "", + "action": "Brake", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "1dffb4da-1be5-49ca-9344-288d594e6a94", + "path": "/s", + "interactions": "", + "processors": "", + "groups": "", + "action": "Brake", + "isComposite": false, + "isPartOfComposite": false } ] } diff --git a/Assets/Scenes/MainMap.unity b/Assets/Scenes/MainMap.unity index 6995f98..ec8087f 100644 --- a/Assets/Scenes/MainMap.unity +++ b/Assets/Scenes/MainMap.unity @@ -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: []