godot-genre-racing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGenre: Racing
类型:赛车
Expert blueprint for racing games balancing physics, competition, and sense of speed.
兼顾物理效果、竞技性与速度感的赛车游戏专家蓝图。
NEVER Do
绝对不要做这些
- NEVER rigid camera attachment — Camera locked to car causes motion sickness. Use lerp with slight delay for smooth follow.
- NEVER skip sense of speed — Increase FOV as speed increases, add camera shake, wind lines, motion blur. Tunnel vision breaks immersion.
- NEVER make physics overly realistic — "Floaty" arcade feel is often more fun than simulation. Increase gravity 2-3x, adjust wheel friction.
- NEVER forget checkpoints — Without validation, players exploit shortcuts. Enforce checkpoint sequence to complete laps.
- NEVER ignore rubber-banding — AI that's too far ahead/behind makes races boring. Adjust AI speed dynamically based on player distance.
- 绝对不要固定镜头绑定 —— 镜头与车辆锁定会导致晕动症。使用lerp(线性插值)并加入轻微延迟实现平滑跟随。
- 绝对不要忽略速度感 —— 随速度增加FOV(视野范围),添加镜头震动、风线条、运动模糊。隧道视野会破坏沉浸感。
- 绝对不要让物理效果过于拟真 —— “轻飘飘”的街机手感往往比拟真模拟更有趣。将重力提高2-3倍,调整车轮摩擦力。
- 绝对不要忘记检查点 —— 没有验证机制的话,玩家会抄近道。强制要求按顺序通过检查点才能完成圈数。
- 绝对不要忽视Rubber-banding AI —— AI对手过于领先或落后会让比赛变得无聊。根据与玩家的距离动态调整AI速度。
Available Scripts
可用脚本
MANDATORY: Read the appropriate script before implementing the corresponding pattern.
必填:在实现对应模式前,请阅读相应脚本。
spline_ai_controller.gd
spline_ai_controller.gd
Path3D-based racing AI. Projects position onto curve, calculates look-ahead for steering, applies throttle based on target speed vs velocity.
基于Path3D的赛车AI。将位置投影到曲线上,计算前瞻点用于转向,根据目标速度与当前速度调整油门。
Core Loop
核心循环
- Race: Player controls a vehicle on a track.
- Compete: Player overtakes opponents or beats the clock.
- Upgrade: Player earns currency/points to buy parts/cars.
- Tune: Player adjusts vehicle stats (grip, acceleration).
- Master: Player learns track layouts and optimal lines.
- 比赛:玩家在赛道上操控车辆。
- 竞技:玩家超越对手或挑战计时。
- 升级:玩家赚取货币/点数购买配件/车辆。
- 调校:玩家调整车辆属性(抓地力、加速度)。
- 精通:玩家熟悉赛道布局与最优路线。
Skill Chain
技能链
| Phase | Skills | Purpose |
|---|---|---|
| 1. Physics | | Car movement, suspension, collisions |
| 2. AI | | Opponent pathfinding, rubber-banding |
| 3. Input | | Analog steering, acceleration, braking |
| 4. UI | | Speedometer, lap timer, minimap |
| 5. Feel | | Speed perception, tire smoke, sparks |
| 阶段 | 技能 | 用途 |
|---|---|---|
| 1. 物理 | | 车辆移动、悬挂、碰撞 |
| 2. AI | | 对手寻路、Rubber-banding机制 |
| 3. 输入 | | 模拟转向、加速、刹车 |
| 4. UI | | 速度表、圈计时器、小地图 |
| 5. 手感 | | 速度感知、轮胎烟雾、火花 |
Architecture Overview
架构概述
1. Vehicle Controller
1. 车辆控制器
Handling the physics of movement.
gdscript
undefined处理移动物理效果。
gdscript
undefinedcar_controller.gd
car_controller.gd
extends VehicleBody3D
@export var max_torque: float = 300.0
@export var max_steering: float = 0.4
func _physics_process(delta: float) -> void:
steering = lerp(steering, Input.get_axis("right", "left") * max_steering, 5 * delta)
engine_force = Input.get_axis("back", "forward") * max_torque
undefinedextends VehicleBody3D
@export var max_torque: float = 300.0
@export var max_steering: float = 0.4
func _physics_process(delta: float) -> void:
steering = lerp(steering, Input.get_axis("right", "left") * max_steering, 5 * delta)
engine_force = Input.get_axis("back", "forward") * max_torque
undefined2. Checkpoint System
2. 检查点系统
Essential for tracking progress and preventing cheating.
gdscript
undefined用于追踪进度和防止作弊的关键系统。
gdscript
undefinedcheckpoint_manager.gd
checkpoint_manager.gd
extends Node
var checkpoints: Array[Area3D] = []
var current_checkpoint_index: int = 0
signal lap_completed
func _on_checkpoint_entered(body: Node3D, index: int) -> void:
if index == current_checkpoint_index + 1:
current_checkpoint_index = index
elif index == 0 and current_checkpoint_index == checkpoints.size() - 1:
complete_lap()
undefinedextends Node
var checkpoints: Array[Area3D] = []
var current_checkpoint_index: int = 0
signal lap_completed
func _on_checkpoint_entered(body: Node3D, index: int) -> void:
if index == current_checkpoint_index + 1:
current_checkpoint_index = index
elif index == 0 and current_checkpoint_index == checkpoints.size() - 1:
complete_lap()
undefined3. Race Manager
3. 比赛管理器
high-level state machine.
gdscript
undefined高级状态机。
gdscript
undefinedrace_manager.gd
race_manager.gd
enum State { COUNTDOWN, RACING, FINISHED }
var current_state: State = State.COUNTDOWN
func start_race() -> void:
# 3.. 2.. 1.. GO!
await countdown()
current_state = State.RACING
start_timer()
undefinedenum State { COUNTDOWN, RACING, FINISHED }
var current_state: State = State.COUNTDOWN
func start_race() -> void:
# 3.. 2.. 1.. GO!
await countdown()
current_state = State.RACING
start_timer()
undefinedKey Mechanics Implementation
关键机制实现
Drifting
漂移
Arcade drifting usually involves faking physics. Reduce friction or apply a sideways force.
gdscript
func apply_drift_mechanic() -> void:
if is_drifting:
# Reduce sideways traction
wheel_friction_slip = 1.0
# Add slight forward boost on exit
else:
wheel_friction_slip = 3.0 # High grip街机风格漂移通常需要模拟物理效果。降低摩擦力或施加侧向力。
gdscript
func apply_drift_mechanic() -> void:
if is_drifting:
# Reduce sideways traction
wheel_friction_slip = 1.0
# Add slight forward boost on exit
else:
wheel_friction_slip = 3.0 # High gripRubber Banding AI
Rubber Banding AI
Keep the race competitive by adjusting AI speed based on player distance.
gdscript
func update_ai_speed(ai_car: VehicleBody3D, player: VehicleBody3D) -> void:
var dist = ai_car.global_position.distance_to(player.global_position)
if ai_car_is_ahead_of_player(ai_car, player):
ai_car.max_speed = base_speed * 0.9 # Slow down
else:
ai_car.max_speed = base_speed * 1.1 # Speed up通过根据与玩家的距离调整AI速度,保持比赛的竞技性。
gdscript
func update_ai_speed(ai_car: VehicleBody3D, player: VehicleBody3D) -> void:
var dist = ai_car.global_position.distance_to(player.global_position)
if ai_car_is_ahead_of_player(ai_car, player):
ai_car.max_speed = base_speed * 0.9 # Slow down
else:
ai_car.max_speed = base_speed * 1.1 # Speed upGodot-Specific Tips
Godot专属技巧
- VehicleBody3D: Godot's built-in node for vehicle physics. It's decent for arcade, but for sims, you might want a custom RayCast suspension.
- Path3D / PathFollow3D: Excellent for simple AI traffic or fixed-path racers (on-rails).
- AudioBus: Use the effect on the AudioListener for realistic passing sounds.
Doppler - SubViewport: Use for the rear-view mirror or minimap texture.
- VehicleBody3D:Godot内置的车辆物理节点。对于街机游戏来说表现不错,但如果是拟真模拟游戏,你可能需要自定义RayCast悬挂系统。
- Path3D / PathFollow3D:非常适合简单的AI车流或固定路线赛车(轨道式)。
- AudioBus:在AudioListener上使用(多普勒)效果实现真实的超车音效。
Doppler - SubViewport:用于实现后视镜或小地图纹理。
Common Pitfalls
常见陷阱
- Floaty Physics: Cars feel like they are on ice. Fix: Increase gravity scale (2x-3x) and adjust wheel friction. Realism < Fun.
- Bad Camera: Camera is rigidly attached to the car. Fix: Use a with a
Marker3Dscript to follow the car smoothly with a slight delay.lerp - Tunnel Vision: No sense of speed. Fix: Increase FOV as speed increases, add camera shake, wind lines, and motion blur.
- 轻飘飘的物理效果:车辆感觉像在冰面上。解决方法:提高重力缩放(2-3倍)并调整车轮摩擦力。趣味性 > 拟真性。
- 糟糕的镜头:镜头与车辆固定绑定。解决方法:使用带有脚本的
lerp实现带轻微延迟的平滑跟随。Marker3D - 缺乏速度感:没有速度的沉浸感。解决方法:随速度增加FOV,添加镜头震动、风线条和运动模糊。
Reference
参考
- Master Skill: godot-master
- 核心技能:godot-master