extends VehicleBody3D
const MAX_STEER = 0.8
const ENGINE_POWER = 300
@onready var camera_pivot: Node3D = $CameraPivot
@onready var camera_3d: Camera3D = $CameraPivot/Camera3D
@warning_ignore(“shadowed_variable_base_class”)
var look_at
Called when the node enters the scene tree for the first time.
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
look_at = global_position
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _physics_process(delta):
steering = move_toward(steering, Input.get_axis(“Right”, “Left”) * MAX_STEER, delta * 2.5)
engine_force = Input.get_axis(“Back”, “Forward”) * ENGINE_POWER
camera_pivot.global_position = camera_pivot.global_position.lerp(global_position, delta * 20.0)
camera_pivot.transform = camera_pivot.transform.interpolate_with(transform, delta * 5.0)
look_at = look_at.lerp(global_position + linear_velocity, delta * 5.0)
camera_3d.look_at(look_at)
What features would you need this “boost” to have? Simplest way I can think of is just make another variable called “boost” and set it to “1”, then in your engine_force code you set it as equal to engine_force = Input.get_axis(“Back”, “Forward”) * ENGINE_POWER * boost. Then make boost equal something greater than “1” at the push of a button. You’d need to define that button in your input map.
Like this:
extends VehicleBody3D
const MAX_STEER = 0.8
const ENGINE_POWER = 300
var BOOST = 1
@onready var camera_pivot: Node3D = $CameraPivot
@onready var camera_3d: Camera3D = $CameraPivot/Camera3D
@warning_ignore(“shadowed_variable_base_class”)
var look_at
Called when the node enters the scene tree for the first time.
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
look_at = global_position
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _physics_process(delta):
steering = move_toward(steering, Input.get_axis(“Right”, “Left”) * MAX_STEER, delta * 2.5)
engine_force = Input.get_axis(“Back”, “Forward”) * ENGINE_POWER * BOOST
camera_pivot.global_position = camera_pivot.global_position.lerp(global_position, delta * 20.0)
camera_pivot.transform = camera_pivot.transform.interpolate_with(transform, delta * 5.0)
look_at = look_at.lerp(global_position + linear_velocity, delta * 5.0)
camera_3d.look_at(look_at)
if is_action_pressed("boost"):
BOOST = 2
else:
BOOST = 1
However, this solution is barebones and inflexible. I advise you experiment a bit to find a solution that suits your project better.