49 lines
945 B
GDScript
49 lines
945 B
GDScript
class_name Character
|
|
extends CharacterBody3D
|
|
|
|
signal jumped
|
|
|
|
@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")
|
|
var controller: Node
|
|
|
|
func _process(delta):
|
|
if direction != Vector3.ZERO:
|
|
angle = atan2(direction.x, direction.z)
|
|
|
|
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
|
|
jumped.emit()
|
|
|
|
func dash():
|
|
print("dash")
|
|
|
|
func attack():
|
|
print("attack")
|