Boost Pads
Lesson 6 of 20 in Coddy's Godot Game: Neon Circuit course.
The glowing arrows on the track are boost pads. Drive over one and the car gets a burst of speed past max_speed.
Keep how long the boost lasts in boost_time. The pads are in the boost_pads group, so the car can find them all:
for pad in get_tree().get_nodes_in_group("boost_pads"):
if position.distance_to(pad.position) < 22.0:
boost_time = maxf(boost_time, 0.4)While the boost lasts, count it down, raise the top speed by 30 percent and push the car forward:
if boost_time > 0.0:
boost_time -= delta
top = max_speed * 1.3
velocity += forward * accel * deltaShow it: the exhaust glows and a flame burns behind the car.
Challenge
Easy- Add
var boost_time := 0.0undervelocity. - After
var top := max_speed, add the boost and then the pad loop. - Set
$Exhaust.emitting = throttle > 0.0 or boost_time > 0.0and$Flame.visible = boost_time > 0.0.
Try it yourself
extends Node2D
@export var accel := 260.0
@export var max_speed := 200.0
@export var turn_speed := 3.2
@export var drag := 0.6
@export var grip := 7.0
var velocity := Vector2.ZERO
@onready var track: Node2D = $"../Track"
func _physics_process(delta: float) -> void:
var throttle := Input.get_axis("move_down", "move_up")
var steer := Input.get_axis("move_left", "move_right")
var forward := Vector2.RIGHT.rotated(rotation)
var speed := velocity.dot(forward)
var top := max_speed
if not track.is_on_road(position):
top = max_speed * 0.45
velocity *= 1.0 - 2.5 * delta
if throttle < 0.0 and speed > 10.0:
velocity += forward * throttle * accel * 1.6 * delta
else:
velocity += forward * throttle * accel * delta
rotation += steer * turn_speed * delta * clampf(absf(speed) / 90.0, 0.0, 1.0) * signf(speed + 0.01)
var side := forward.orthogonal()
velocity -= side * velocity.dot(side) * minf(1.0, grip * delta)
velocity *= 1.0 - drag * delta
if velocity.length() > top:
velocity = velocity.move_toward(velocity.limit_length(top), accel * 2.0 * delta)
position += velocity * delta
$Exhaust.emitting = throttle > 0.0
All lessons in Godot Game: Neon Circuit
Practice on your own: Godot playground