killbox/bak/player_movement.gd
Nikolai Rodionov f17726240d
Trying something that will probably never happen
Signed-off-by: Nikolai Rodionov <allanger@badhouseplants.net>
2025-05-31 23:39:45 +02:00

38 lines
1.2 KiB
GDScript

extends CharacterBody3D
const SPEED = 8.0
const JUMP_VELOCITY = 7
var camera_sens: float = 0.005
@onready var h_rotation: Node3D = $"H-Rotation"
func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
var look_dir = event.relative * 1
rotation.y -= look_dir.x * camera_sens * 1.0
h_rotation.rotation.x = clamp(
h_rotation.rotation.x - look_dir.y * camera_sens * 1.0, -1.5, 1.5
)
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
else:
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir := Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()