59 lines
1.6 KiB
GDScript
59 lines
1.6 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 var cooldown: float = 1
|
|
|
|
@export_group("Children")
|
|
@export var head: Node3D
|
|
@export var anim: AnimationPlayer
|
|
@export var particules: GPUParticles3D
|
|
|
|
@export var time_hand: float= 0
|
|
|
|
|
|
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:
|
|
time_hand += delta
|
|
# 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") and time_hand >= cooldown):
|
|
time_hand = 0
|
|
var vect
|
|
if(checkpoint == null):
|
|
vect = Vector3.DOWN * SPEED_PARTICULES
|
|
else:
|
|
vect = (checkpoint.position - position).normalized() * SPEED_PARTICULES
|
|
particules.process_material.set("gravity", vect)
|
|
particules.emitting = true
|
|
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()
|