Starting to add a sprint, will figure out how to hook in the run animation next

This commit is contained in:
LAPTOP-4D0S2MHQ\pillb 2026-02-13 02:48:07 -06:00
parent d1fade919c
commit b3287ccf6f

View File

@ -4,11 +4,11 @@ extends RigidBody3D
# of collisions. So that's why we're using a RigidBody3D instead.
const MOVE_SPEED := 8.0
const SPRINT_MOVE_SPEED :=13
const ACCELLERATION := 30.0
const DECELLERATION := 40.0
const JUMP_SPEED := 4.0
const MAX_NUMBER_OF_JUMPS := 2
const MIN_FOV := 10
const MAX_FOV := 180
const ZOOM_FACTOR := 1.1 # Zoom out when >1, in when < 1
@ -37,7 +37,9 @@ var _jump_triggered := false
@export var anim_idle_name := "Idle"
@export var anim_walk_name := "Walk"
@export var anim_jump_name := "Jump"
@export var anim_run_name := "Run"
@export var anim_walk_speed_threshold := 0.25
@export var anim_sprint_speed_threshold := 10.0
var jump_sound = preload("res://assets/audio/jump.ogg")
var audio_player = AudioStreamPlayer.new()
@ -117,8 +119,13 @@ func _integrate_forces(state):
right = _last_move_right
var dir := (right * input2v.x + forward * input2v.y).normalized()
var target_v := dir * MOVE_SPEED
# Sprinting
if Input.is_key_pressed(KEY_SHIFT):
target_v = dir * SPRINT_MOVE_SPEED
var ax := ACCELLERATION if dir != Vector3.ZERO else DECELLERATION
linear_velocity.x = move_toward(linear_velocity.x, target_v.x, ax * state.step)
linear_velocity.z = move_toward(linear_velocity.z, target_v.z, ax * state.step)
@ -188,6 +195,10 @@ func _update_animation(on_floor: bool, velocity: Vector3) -> void:
if _anim_player.current_animation != anim_jump_name:
_anim_player.play(anim_jump_name)
return
if on_floor and horizontal_speed > anim_sprint_speed_threshold and _anim_player.has_animation(anim_run_name):
if _anim_player.current_animation != anim_walk_name:
_anim_player.play(anim_walk_name)
return
if horizontal_speed > anim_walk_speed_threshold and _anim_player.has_animation(anim_walk_name):
if _anim_player.current_animation != anim_walk_name:
_anim_player.play(anim_walk_name)
@ -233,4 +244,3 @@ func exit_vehicle(exit_point: Node3D, vehicle_camera: Camera3D) -> void:
vehicle_camera.current = false
if cam:
cam.current = true