cawez_puzzlebox/player/player_moves_float.gd
2024-06-29 21:57:20 -04:00

80 lines
2.8 KiB
GDScript

extends RigidBody3D
var mouse_input = Vector3(0.0,0.0,0.0)
var raw_mouse_input = Vector3(0.0,0.0,0.0)
var alpha = 10
var can_float = 0.0
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
# Sets up the input variables
# Cursor input
var tmp = Input.get_last_mouse_velocity() * delta * Globals.sensitivity
raw_mouse_input = Vector3(tmp.x, tmp.y, Input.get_axis("more", "less") / 100.0)
# Zoom in/out
var scroll_input = 0.5 * int(Input.is_action_just_released("out")) - int(Input.is_action_just_released("in"))
# WASD
var move_input := Vector3.ZERO
# Filters the mouse input using exponential interpolation
mouse_input.x = mouse_input.x * exp(-alpha * delta) + raw_mouse_input.x * (1.0 - exp(-alpha * delta))
mouse_input.y = mouse_input.y * exp(-alpha * delta * 3) + raw_mouse_input.y * (1.0 - exp(-alpha * delta * 3))
#mouse_input.z = mouse_input.z * exp(-alpha * delta * 3) + raw_mouse_input.z * (1.0 - exp(-alpha * delta * 3))
mouse_input.z = raw_mouse_input.z
# Assigns the controls input
move_input.x = Input.get_axis("forward", "backwards")
move_input.y = -Input.get_axis("right", "left")
move_input.z = Input.get_axis("up", "alternate")
move_input = move_input.normalized()
# Funky FOV thing
if (!Globals.next && !Globals.restart):
# Not doing anything special? Track FOV
$gimbal/stick/camera.fov = $gimbal/stick/camera.fov * exp(-0.5 * delta) + Globals.fov * (1.0 - exp(-0.5 * delta))
else:
# Either skipping / restarting : explode FOV
$gimbal/stick/camera.fov = $gimbal/stick/camera.fov * exp(-7 * delta) + 179 * (1.0 - exp(-7 * delta))
# Finished animation?
if $gimbal/stick/camera.fov > 175:
# Was it triggered by a restart or by a next?
if Globals.restart:
# Reset vars and load active scene
Globals.restart = false
Globals.next = false
LevelLoader.redo()
else:
# Reset vars and load next scene
Globals.restart = false
Globals.next = false
LevelLoader.next()
# Rotates the camera
$gimbal.rotate_object_local(quaternion * Vector3.LEFT, mouse_input.y)
$gimbal.rotate_object_local(quaternion * Vector3.FORWARD, mouse_input.x)
$gimbal.rotate_object_local(quaternion * Vector3.UP, mouse_input.z)
# Zooms in/out
$gimbal/stick/camera.translate(Vector3(0,0,scroll_input))
$gimbal/stick/camera.position.z = clamp($gimbal/stick/camera.position.z, 0, 50)
# Default size is 0.85 = 1m
$player_model.scale = Vector3(1,1,1) * clamp($gimbal/stick/camera.position.z/2, 0, 0.85)
# Movement + animation
# Makes sure the player is in a moveable area
if can_float != 0:
linear_damp = 2
apply_central_force($gimbal.quaternion * Vector3(move_input.y, -move_input.x, -move_input.z) * delta * 2000.0)
if move_input != Vector3.ZERO:
$player_model.rotate(move_input, delta * 5)
else:
linear_damp = 0.0
print(linear_velocity.length())