diff --git a/Assets/Karting/Scripts/KartSystems/ArcadeKart.cs b/Assets/Karting/Scripts/KartSystems/ArcadeKart.cs index 7dd6f2a..2db09e9 100644 --- a/Assets/Karting/Scripts/KartSystems/ArcadeKart.cs +++ b/Assets/Karting/Scripts/KartSystems/ArcadeKart.cs @@ -78,18 +78,26 @@ namespace KartGame.KartSystems public ArcadeKart.Stats baseStats = new ArcadeKart.Stats { - TopSpeed = 10f, - Acceleration = 5f, + TopSpeed = 22.5f, + Acceleration = 8f, AccelerationCurve = 4f, - Braking = 10f, + Braking = 12f, ReverseAcceleration = 5f, - ReverseSpeed = 5f, - Steer = 5f, - CoastingDrag = 4f, - Grip = .95f, + ReverseSpeed = 4f, + Steer = 2f, + CoastingDrag = 0.5f, + Grip = .9f, AddedGravity = 1f, }; + [Header("扩展系统")] + [Tooltip("手动变速箱(可选)")] + public KartManualGearbox ManualGearbox; + [Tooltip("油量系统(可选)")] + public KartFuelSystem FuelSystem; + [Tooltip("是否启用档位对速度/加速度的影响")] + public bool UseGearboxModifiers = true; + [Header("车辆视觉")] public List m_VisualWheels; // 视觉轮子列表 @@ -135,11 +143,11 @@ namespace KartGame.KartSystems [Header("悬挂系统")] [Tooltip("车身与轮子之间允许的最大伸缩长度")] [Range(0.0f, 1.0f)] - public float SuspensionHeight = 0.2f; + public float SuspensionHeight = 0.3f; [Range(10.0f, 100000.0f), Tooltip("数值越高,悬挂越硬")] - public float SuspensionSpring = 20000.0f; + public float SuspensionSpring = 15000.0f; [Range(0.0f, 5000.0f), Tooltip("数值越高,车辆平衡恢复得越快")] - public float SuspensionDamp = 500.0f; + public float SuspensionDamp = 2000.0f; [Tooltip("调整轮子相对于车身垂直位置的偏移")] [Range(-1.0f, 1.0f)] public float WheelsPositionVerticalOffset = 0.0f; @@ -295,6 +303,9 @@ namespace KartGame.KartSystems // 应用增益道具计算最终属性 TickPowerups(); + // 应用档位修正(在TickPowerups之后,确保powerup已叠加) + ApplyGearboxModifiers(); + // 更新刚体重心 Rigidbody.centerOfMass = transform.InverseTransformPoint(CenterOfMass.position); @@ -350,6 +361,32 @@ namespace KartGame.KartSystems m_FinalStats.Grip = Mathf.Clamp(m_FinalStats.Grip, 0, 1); } + /// + /// 根据当前档位修正最终速度/加速度属性(仅在FixedUpdate中临时应用) + /// + void ApplyGearboxModifiers() + { + if (!UseGearboxModifiers || ManualGearbox == null) return; + + var setting = ManualGearbox.GetCurrentSetting(); + float speedMult = setting.SpeedMultiplier; + float accelMult = setting.AccelerationMultiplier; + + // 倒车使用独立的倒车速度倍率 + if (ManualGearbox.CurrentGear == GearMode.Reverse) + { + m_FinalStats.ReverseSpeed *= speedMult > 0f ? speedMult : 1f; + m_FinalStats.ReverseAcceleration *= accelMult; + } + else if (ManualGearbox.CurrentGear != GearMode.Neutral) + { + m_FinalStats.TopSpeed *= speedMult; + m_FinalStats.Acceleration *= accelMult; + m_FinalStats.ReverseAcceleration *= accelMult; + } + // Neutral: 不修改速度上限,但 MoveVehicle 中会把 accelerate 置 0 + } + void GroundAirbourne() { // 在空中时下落得更快 @@ -404,6 +441,22 @@ namespace KartGame.KartSystems // 车辆移动核心逻辑 void MoveVehicle(float accelerate, bool brake, float turnInput) { + // 引擎未启动或燃油耗尽:切断动力但保留滑行/刹车物理 + bool engineCanDrive = Input.EngineOn && (FuelSystem == null || !FuelSystem.IsEmpty); + bool isNeutral = Input.CurrentGear == GearMode.Neutral; + + if (!engineCanDrive) + { + accelerate = 0f; + isNeutral = true; + } + + // 空挡时引擎动力不传递到车轮(仅保留滑行和刹车) + if (isNeutral) + { + accelerate = 0f; + } + // 合并加速和刹车输入 float accelInput = accelerate - (brake ? 1.0f : 0.0f); diff --git a/Assets/Karting/Scripts/KartSystems/Inputs/BTInput.cs b/Assets/Karting/Scripts/KartSystems/Inputs/BTInput.cs index a16fe4a..89f8113 100644 --- a/Assets/Karting/Scripts/KartSystems/Inputs/BTInput.cs +++ b/Assets/Karting/Scripts/KartSystems/Inputs/BTInput.cs @@ -11,11 +11,13 @@ namespace KartGame.KartSystems Accelerate = this.Accelerate, TurnInput = this.Turn, Brake = this.Brake, + Handbrake = this.Handbrake, CurrentGear = this.Gear, CurrentDrive = this.DriveTrain, LightsOn = this.Lights, - EngineOn = this.EngineActive + EngineOn = this.EngineActive, + Horn = this.Horn }; } } -} \ No newline at end of file +} diff --git a/Assets/Karting/Scripts/KartSystems/Inputs/BaseInput.cs b/Assets/Karting/Scripts/KartSystems/Inputs/BaseInput.cs index bc1b349..e1f5042 100644 --- a/Assets/Karting/Scripts/KartSystems/Inputs/BaseInput.cs +++ b/Assets/Karting/Scripts/KartSystems/Inputs/BaseInput.cs @@ -1,20 +1,53 @@ -using UnityEngine; +using UnityEngine; namespace KartGame.KartSystems { - public enum GearMode { Automatic, Manual, Neutral, Reverse } + /// + /// 车辆驱动模式(前驱/后驱/四驱) + /// public enum DriveTrainMode { ForwardWheelDrive, RearWheelDrive, AllWheelDrive } + /// + /// 手动档位:R倒车, N空挡, 1~5前进档 + /// + public enum GearMode + { + Reverse = -1, + Neutral = 0, + First = 1, + Second = 2, + Third = 3, + Fourth = 4, + Fifth = 5 + } + + /// + /// 车辆运行状态(与Animator状态机对应) + /// + public enum VehicleState + { + Off = 0, // 熄火 + Ignition = 1, // 点火中 + Idle = 2, // 怠速 + IdleAccelerate = 3,// 怠速加油(空挡轰油门) + Cruise = 4, // 巡航 + CruiseBrake = 5, // 巡航刹车 + Reverse = 6, // 倒车 + Stuck = 7 // 陷地 + } + [System.Serializable] public struct InputData { - public float Accelerate; - public float TurnInput; - public bool Brake; - public GearMode CurrentGear; + public float Accelerate; // 油门输入 0~1 + public float TurnInput; // 转向输入 -1~1 + public bool Brake; // 脚刹 + public bool Handbrake; // 手刹 + public GearMode CurrentGear; // 当前档位 public DriveTrainMode CurrentDrive; - public bool LightsOn; //灯光状态 - public bool EngineOn; //引擎状态 + public bool LightsOn; // 大灯开关 + public bool EngineOn; // 引擎开关 + public bool Horn; // 喇叭 } public interface IInput @@ -24,23 +57,26 @@ namespace KartGame.KartSystems public abstract class BaseInput : MonoBehaviour, IInput { - [Header("Basic Controls")] + [Header("基础移动")] public float Accelerate; public float Turn; public bool Brake; + public bool Handbrake; - [Header("Advanced Simulation")] - public GearMode Gear = GearMode.Automatic; + [Header("高级模拟")] + public GearMode Gear = GearMode.Neutral; public DriveTrainMode DriveTrain = DriveTrainMode.AllWheelDrive; public bool Lights; public bool EngineActive = true; + public bool Horn; // --- 基础移动控制 --- - public void SetMovement(float accel, float turn, bool brake) + public void SetMovement(float accel, float turn, bool brake, bool handbrake = false) { this.Accelerate = accel; this.Turn = turn; this.Brake = brake; + this.Handbrake = handbrake; } // --- 档位控制 --- @@ -67,6 +103,12 @@ namespace KartGame.KartSystems this.EngineActive = state; } + // --- 喇叭控制 --- + public void SetHorn(bool state) + { + this.Horn = state; + } + public abstract InputData GenerateInput(); } -} \ No newline at end of file +} diff --git a/Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/NLD/GetJoystickContext.cs b/Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/NLD/GetJoystickContext.cs index f3450bf..e108c72 100644 --- a/Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/NLD/GetJoystickContext.cs +++ b/Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/NLD/GetJoystickContext.cs @@ -1,3 +1,4 @@ +#if ENABLE_INPUT_SYSTEM using NodeCanvas.Framework; using ParadoxNotion.Design; using UnityEngine; @@ -31,4 +32,5 @@ namespace NLD.Nodes outputY.value = pos.y; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/NLD/SetVehicleInput.cs b/Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/NLD/SetVehicleInput.cs index 63eb97a..e216346 100644 --- a/Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/NLD/SetVehicleInput.cs +++ b/Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/NLD/SetVehicleInput.cs @@ -1,18 +1,18 @@ using NodeCanvas.Framework; using ParadoxNotion.Design; -using KartGame.KartSystems; // 确保指向你的载具命名空间 - +using KartGame.KartSystems; namespace NLD.Nodes { [Category("VehicleControl")] - [Description("将 NodeCanvas 黑板中的数据实时同步到 BaseInput 抽象层")] + [Description("将 NodeCanvas 黑板中的数据实时同步到 BaseInput 抽象层(含手动档、手刹、喇叭)")] public class SetVehicleInput : ActionTask { [RequiredField] public BBParameter accelerate; public BBParameter turn; public BBParameter brake; + public BBParameter handbrake; [Header("档位和传动")] public BBParameter gear; @@ -21,21 +21,17 @@ namespace NLD.Nodes [Header("电气与启停")] public BBParameter headlights; public BBParameter engineOn; + public BBParameter horn; - // OnUpdate 会在行为树运行到该节点时每帧执行 protected override void OnUpdate() { if (agent == null) return; - // 1. 同步基础移动 - agent.SetMovement(accelerate.value, turn.value, brake.value); - - // 2. 同步档位与驱动 + agent.SetMovement(accelerate.value, turn.value, brake.value, handbrake.value); agent.SetGear(gear.value); agent.SetDriveMode(driveMode.value); - - // 3. 同步其他系统 agent.SetLights(headlights.value); agent.SetEngineStatus(engineOn.value); + agent.SetHorn(horn.value); } } -} \ No newline at end of file +}