33 lines
935 B
GDScript
33 lines
935 B
GDScript
extends CharacterBody3D
|
|
class_name Player
|
|
|
|
var input: PlayerInputData
|
|
|
|
const SPEED = 5.0
|
|
const JUMP_VELOCITY = 4.5
|
|
|
|
@onready var model = %fox
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if not model.is_busy():
|
|
var direction := input.walk_dir
|
|
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)
|
|
if direction.length() > 0.01:
|
|
var target := global_transform.looking_at(global_position + input.walk_dir, Vector3(0.0, 1.0, 0.0)).basis.get_euler().y
|
|
var current_euler := global_basis.get_euler()
|
|
current_euler.y = lerp_angle(current_euler.y, target, delta * 20.0)
|
|
global_basis = Basis.from_euler(current_euler)
|
|
|
|
model.walk()
|
|
else:
|
|
model.idle()
|
|
if input.jumping:
|
|
model.pounce()
|
|
|
|
position += model.global_transform.basis * model.root_motion()
|
|
move_and_slide()
|