Godot Version
4.7.2
Question
I’m working on a sprint mechanic in my game where you can hold shift to increase the player’s movement speed, but I’ve run into an issue with the code. To prevent the sprint mechanic from working while the player is airborne, I tried to put an “and” inside the if condition, but this resulted in the whole statement getting a red highlight with the error message “Expected ‘:’ after ‘if’ condition”.
I’d greatly appreciate it if anyone could give some advice on how I can fix this.
extends CharacterBody3D
@export var walk_speed = 5.0
@export var run_speed = 10.0
var speed = 5.0
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Change speed depending on if run input is active.
if Input is_action_pressed("run") and is_on_floor():
speed = run_speed
else
speed = walk_speed