2024-01-18 22:35:17 +00:00
|
|
|
class_name Character
|
|
|
|
extends CharacterBody3D
|
|
|
|
|
|
|
|
@export var model: Node3D
|
|
|
|
@export var move_speed: float = 4.5
|
|
|
|
@export var rotation_speed: float = 20.0
|
|
|
|
|
|
|
|
const JUMP_VELOCITY := 4.5
|
|
|
|
const DECELERATE := 0.75
|
|
|
|
|
|
|
|
var direction: Vector3
|
|
|
|
var angle: float
|
|
|
|
var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity")
|
2024-01-26 16:14:20 +00:00
|
|
|
var controller: Node
|
2024-01-18 22:35:17 +00:00
|
|
|
|
|
|
|
func _process(delta):
|
2024-01-26 16:14:20 +00:00
|
|
|
if direction != Vector3.ZERO:
|
2024-01-18 22:35:17 +00:00
|
|
|
angle = atan2(direction.x, direction.z)
|
2024-01-26 16:14:20 +00:00
|
|
|
|
2024-01-18 22:35:17 +00:00
|
|
|
model.rotation.y = lerp_angle(model.rotation.y, angle, rotation_speed * delta)
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
if direction:
|
|
|
|
velocity.x = direction.x * move_speed
|
|
|
|
velocity.z = direction.z * move_speed
|
|
|
|
else:
|
|
|
|
velocity.x *= DECELERATE
|
|
|
|
velocity.z *= DECELERATE
|
|
|
|
|
|
|
|
if !is_on_floor():
|
|
|
|
velocity.y -= gravity * delta
|
|
|
|
|
|
|
|
move_and_slide()
|
|
|
|
|
|
|
|
func jump():
|
|
|
|
if !is_on_floor():
|
|
|
|
return
|
|
|
|
|
|
|
|
velocity.y = JUMP_VELOCITY
|
|
|
|
|
|
|
|
func dash():
|
|
|
|
print("dash")
|
|
|
|
|
|
|
|
func attack():
|
|
|
|
print("attack")
|