2023-10-05 18:02:23 +00:00
|
|
|
extends CharacterBody3D
|
|
|
|
|
2023-10-08 18:54:58 +00:00
|
|
|
const speed_walk = 1.0
|
|
|
|
const speed_run = 4.0
|
2023-10-05 18:02:23 +00:00
|
|
|
const JUMP_VELOCITY = 4.5
|
|
|
|
const lent = 0.05
|
2023-10-08 18:54:58 +00:00
|
|
|
var action_speed= false
|
2023-10-05 18:02:23 +00:00
|
|
|
|
|
|
|
@onready var animation_player = $visuals/raference/AnimationPlayer
|
|
|
|
@onready var visuals = $visuals
|
|
|
|
@onready var perso = $visuals/raference
|
|
|
|
@export var fall_acceleration = 75
|
|
|
|
|
|
|
|
var angular_speed = PI
|
|
|
|
var target_velocity = Vector3.ZERO
|
|
|
|
var jump_force = 10
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
var direction = Vector3.ZERO
|
|
|
|
var perso_y = perso.global_transform.basis.y
|
|
|
|
var perso_z = perso.global_transform.basis.z
|
|
|
|
#var perso_x = perso.global_transform.basis.x
|
|
|
|
|
|
|
|
if Input.is_action_pressed("ui_right"):
|
|
|
|
visuals.rotation -= perso_y * lent
|
|
|
|
if Input.is_action_pressed("ui_left"):
|
|
|
|
visuals.rotation += perso_y * lent
|
|
|
|
if Input.is_action_pressed("ui_down"):
|
|
|
|
direction -= perso_z
|
2023-10-08 18:54:58 +00:00
|
|
|
animation_player.play_backwards( "raference_march")
|
|
|
|
if Input.is_action_just_pressed("ui_change_speed"):
|
|
|
|
action_speed = !action_speed
|
2023-10-05 18:02:23 +00:00
|
|
|
if Input.is_action_pressed("ui_up"):
|
2023-10-08 18:54:58 +00:00
|
|
|
if action_speed:
|
|
|
|
direction += perso_z * speed_run
|
|
|
|
animation_player.play( "raference_run")
|
|
|
|
else:
|
|
|
|
direction += perso_z
|
|
|
|
animation_player.play( "raference_march")
|
|
|
|
if Input.is_action_pressed("ui_camera"):
|
|
|
|
$camerapivot/Camera3D.global_transform = perso.direction
|
2023-10-05 18:02:23 +00:00
|
|
|
if direction.x == 0 and direction.z == 0:
|
|
|
|
animation_player.play( "raference_idle")
|
|
|
|
if Input.is_action_pressed("ui_cancel"):
|
|
|
|
get_tree().quit()
|
|
|
|
|
|
|
|
#if direction != Vector3.ZERO:
|
|
|
|
#direction = direction.normalized()
|
|
|
|
#perso_y.look_at(position + direction, Vector3.UP)
|
|
|
|
|
2023-10-08 18:54:58 +00:00
|
|
|
target_velocity.x = direction.x * speed_walk
|
|
|
|
target_velocity.z = direction.z * speed_walk
|
2023-10-05 18:02:23 +00:00
|
|
|
|
|
|
|
if is_on_floor() and Input.is_action_just_pressed("ui_jump"):
|
|
|
|
target_velocity.y = jump_force
|
|
|
|
|
|
|
|
# Vertical Velocity
|
|
|
|
if not is_on_floor():
|
|
|
|
target_velocity.y = target_velocity.y - (fall_acceleration * delta)
|
|
|
|
|
|
|
|
velocity = target_velocity
|
|
|
|
move_and_slide()
|