somewhat working console, fully developed from the ground up some things work with it, but its still pretty buggy currently runs on global autoload because its the easiest way rn, later on have to change it so that only if the player is in the game and console is enabled it can be toggled
99 lines
4.2 KiB
GDScript
99 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: CharacterBody3D = $"../.."
|
|
@onready var player_state: Node = %PlayerState
|
|
@onready var player_manager: Node = %PlayerManager
|
|
@onready var procedural_camera_mover: Node = %ProceduralCameraMover
|
|
@onready var player_hit_box: CollisionShape3D = $"../../PlayerHitBox"
|
|
@onready var sound_controller: Node = %SoundController
|
|
@onready var ui: Control = %PlayerUi
|
|
|
|
|
|
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 and not Console.toggled:
|
|
if Input.is_action_just_pressed("jump") and player.is_on_floor() and player_manager.stamina > JUMP_STAMINA_COST:
|
|
player.velocity.y = JUMP_VELOCITY
|
|
player_manager.stamina -= JUMP_STAMINA_COST
|
|
player_manager.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_manager.stamina > 0:
|
|
target_speed *= SPRINT_MULTIPLIER
|
|
player_state.is_running(true)
|
|
player_manager.stamina -= delta * SPRINT_STAMINA_COST
|
|
player_manager.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)
|
|
|
|
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()
|
|
procedural_camera_mover.do(delta)
|
|
|
|
# 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)
|
|
#
|