Files
Idiot_du_Village/script/player.gd
2025-01-18 10:43:11 +01:00

54 lines
1.4 KiB
GDScript

extends CharacterBody3D
@export var SPEED: float = 10.0
@export var SENSI : float = 0.005
@export var SPEED_PARTICULES: float = 1;
@export var checkpoint:Node3D = null
@export_group("Children")
@export var head: Node3D
@export var anim: AnimationPlayer
@export var particules: GPUParticles3D
func _ready() -> void:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
add_to_group("player")
func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
head.rotate_x(-event.relative.y * SENSI)
rotate_y(-event.relative.x * SENSI)
head.rotation.x = clamp(head.rotation.x, -PI/2, PI/2)
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
if velocity.y < 0:
velocity += get_gravity() * delta * 2
else:
velocity += get_gravity() * delta * 3
if (Input.is_action_just_pressed("interact")):
var vect
if(checkpoint == null):
vect = Vector3.DOWN * SPEED_PARTICULES
else:
vect = (checkpoint.position - position).normalized() * SPEED_PARTICULES
particules.process_material.set("gravity", vect)
anim.play("finger")
var input_dir := Input.get_vector("left", "right", "up", "down")
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()