title says all. must fix some audio related bugs, and fix the breathing mechanic, so that the character breathes even when not staying still, but the breathing should sync to the camera bobbing
101 lines
4.2 KiB
GDScript
101 lines
4.2 KiB
GDScript
extends Node
|
|
|
|
@export_category("Movement")
|
|
@export var SPEED = 5.0 ##base walking speed
|
|
@export var SPRINT_MULTIPLIER = 1.5 ##how much faster should you move, when sprinting
|
|
@export var SPRINT_STAMINA_COST = 10.0 ##how much stamina should be consumed each frame while sprinting (delta * SPRINT_STAMINA_COST)
|
|
@export var CROUCH_SPEED_MULTIPLIER = .5 ##how much slower you should be going while crouching
|
|
|
|
@export_category("Jump")
|
|
@export var JUMP_VELOCITY = 4.5 ##how high you can jump
|
|
@export var JUMP_STAMINA_COST = 10 ##how much stamina each jump consumes
|
|
|
|
@export_category("Camera")
|
|
@export var LOOK_SENSITIVITY = 1.0 ##camera sensitivity
|
|
@export var CAMERA_VELOCITY_MULTIPLIER = 1.5 ##how heavy should the UI movement feel
|
|
|
|
|
|
@onready var camera_pivot: Node3D = %CameraPivot
|
|
@onready var player_camera: Camera3D = %PlayerCamera
|
|
@onready var player: PlayerCharacter = $"../.."
|
|
@onready var player_state: Node = %PlayerState
|
|
@onready var player_properties: Node = %PlayerProperties
|
|
@onready var procedural_camera_mover: Node = %ProceduralCameraMover
|
|
@onready var player_hit_box: CollisionShape3D = $"../../PlayerHitBox"
|
|
@onready var sound_controller: Node = %SoundController
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if not player.is_on_floor():
|
|
player.velocity += player.get_gravity() * delta
|
|
|
|
if not player_state.in_menu:
|
|
if Input.is_action_just_pressed("jump") and player.is_on_floor() and player_properties.stamina > JUMP_STAMINA_COST:
|
|
sound_controller.play_jump_sound()
|
|
player.velocity.y = JUMP_VELOCITY
|
|
player_properties.stamina -= JUMP_STAMINA_COST
|
|
player_properties.stamina_recharge_off()
|
|
|
|
var input_dir = Input.get_vector("left", "right", "forward", "backward")
|
|
#var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
var lean_dir = -Input.get_axis("lean_left", "lean_right") * .1
|
|
|
|
if lean_dir:
|
|
camera_pivot.rotation.z = lerpf(camera_pivot.rotation.z, lean_dir, delta*10)
|
|
camera_pivot.position.x = lerpf(camera_pivot.position.x, -lean_dir * 5, delta * 7)
|
|
else:
|
|
camera_pivot.rotation.z = lerpf(camera_pivot.rotation.z, 0, delta*10)
|
|
camera_pivot.position.x = lerpf(camera_pivot.position.x, 0, delta * 7)
|
|
|
|
var target_speed = SPEED
|
|
var is_moving = input_dir != Vector2.ZERO
|
|
|
|
if Input.is_action_pressed("crouch"):
|
|
player_hit_box.shape.height = lerpf(player_hit_box.shape.height, .5, delta * 5)
|
|
target_speed *= CROUCH_SPEED_MULTIPLIER
|
|
player_state.is_crouched(true)
|
|
else:
|
|
player_hit_box.shape.height = lerpf(player_hit_box.shape.height, 2, delta * 10)
|
|
player_state.is_crouched(false)
|
|
|
|
if Input.is_action_pressed("sprint") and player_properties.stamina > 0:
|
|
target_speed *= SPRINT_MULTIPLIER
|
|
player_state.is_running(true)
|
|
player_properties.stamina -= delta * SPRINT_STAMINA_COST
|
|
player_properties.stamina_recharge_off()
|
|
else:
|
|
player_state.is_running(false)
|
|
|
|
#apply motion
|
|
var local_vel = player.transform.basis.inverse() * player.velocity
|
|
var target_local_vel = Vector3(player_camera.transform.basis * Vector3(input_dir.x, 0, input_dir.y)) * target_speed
|
|
var accel_rate = 6.0 if is_moving else 9.0
|
|
local_vel.x = lerpf(local_vel.x, target_local_vel.x, delta * accel_rate)
|
|
local_vel.z = lerpf(local_vel.z, target_local_vel.z, delta * accel_rate)
|
|
|
|
var global_horizontal = player.transform.basis * local_vel
|
|
player.velocity.x = global_horizontal.x
|
|
player.velocity.z = global_horizontal.z
|
|
|
|
if is_moving and not player_state.running and not player_state.crouching:
|
|
player_state.is_walking(true)
|
|
else:
|
|
player_state.is_walking(false)
|
|
|
|
procedural_camera_mover.do(delta)
|
|
else:
|
|
player.velocity.x = lerpf(player.velocity.x, 0, delta * 10)
|
|
player.velocity.z = lerpf(player.velocity.z, 0, delta * 10)
|
|
|
|
player.move_and_slide()
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
#func _process(delta: float) -> void:
|
|
#_mouse_motion.y = clamp(_mouse_motion.y, -1560, 1560)
|
|
#player.transform.basis = Basis.from_euler(Vector3(0, _mouse_motion.x * -0.001 * LOOK_SENSITIVITY, 0))
|
|
#player.transform.basis = lerp(player_camera.transform.basis, Basis.from_euler(Vector3(_mouse_motion.y * -0.001 * LOOK_SENSITIVITY, 0, 0)), delta * 10)
|
|
#
|