2026-05-08 14:22:54 +00:00
|
|
|
extends CharacterBody3D
|
|
|
|
|
|
2026-05-09 17:18:11 +00:00
|
|
|
const SPEED = 3.5
|
2026-05-08 14:22:54 +00:00
|
|
|
const JUMP_VELOCITY = 4.5
|
|
|
|
|
|
|
|
|
|
var walk_animation_time = 0
|
2026-05-08 16:33:09 +00:00
|
|
|
var face_rotation = null
|
|
|
|
|
var face_left = false
|
2026-05-08 14:22:54 +00:00
|
|
|
|
2026-05-09 15:38:52 +00:00
|
|
|
var combatable = true
|
|
|
|
|
|
2026-05-09 17:18:11 +00:00
|
|
|
var iframes = 0
|
2026-05-09 18:16:23 +00:00
|
|
|
var knockback_time = 0
|
2026-05-09 17:18:11 +00:00
|
|
|
var health = 100
|
|
|
|
|
|
2026-05-08 14:22:54 +00:00
|
|
|
@onready var game = get_parent()
|
2026-05-08 16:33:09 +00:00
|
|
|
@onready var camera = game.get_node("PlayerCamera")
|
2026-05-08 14:22:54 +00:00
|
|
|
|
2026-05-09 17:18:11 +00:00
|
|
|
func hit_me():
|
|
|
|
|
iframes = 0.5
|
|
|
|
|
health -= 10
|
2026-05-09 18:16:23 +00:00
|
|
|
|
|
|
|
|
func on_hit(hitter: Node3D = null) -> void:
|
|
|
|
|
iframes = 0.8
|
|
|
|
|
|
|
|
|
|
if hitter:
|
|
|
|
|
knockback_time = 0.25
|
|
|
|
|
velocity += hitter.global_position.direction_to(global_position) * 8
|
|
|
|
|
velocity.y = 0
|
2026-05-09 17:18:11 +00:00
|
|
|
|
2026-05-08 14:22:54 +00:00
|
|
|
func _ready() -> void:
|
|
|
|
|
$DreamerBody.look_at(game.get_node("PlayerCamera").global_position)
|
|
|
|
|
$DreamerBody.rotation.x = 0
|
2026-05-08 16:33:09 +00:00
|
|
|
face_rotation = $DreamerBody.rotation.y
|
2026-05-09 17:18:11 +00:00
|
|
|
|
|
|
|
|
LimboConsole.register_command(hit_me)
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
if iframes > 0:
|
|
|
|
|
iframes -= delta
|
|
|
|
|
$DreamerBody/Body.modulate.a = 0.5
|
|
|
|
|
else:
|
|
|
|
|
$DreamerBody/Body.modulate.a = 1
|
2026-05-09 18:16:23 +00:00
|
|
|
|
|
|
|
|
if knockback_time > 0:
|
|
|
|
|
knockback_time -= delta
|
2026-05-08 14:22:54 +00:00
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
|
if not is_on_floor():
|
|
|
|
|
velocity += get_gravity() * delta
|
2026-05-08 16:33:09 +00:00
|
|
|
|
2026-05-09 15:38:52 +00:00
|
|
|
var viewport_half = (get_viewport().get_visible_rect().size / 2.0)
|
|
|
|
|
var player_position = camera.unproject_position(global_transform.origin)
|
|
|
|
|
|
2026-05-08 16:33:09 +00:00
|
|
|
if face_left:
|
|
|
|
|
$DreamerBody.rotation.y = face_rotation + deg_to_rad(180)
|
|
|
|
|
else:
|
|
|
|
|
$DreamerBody.rotation.y = face_rotation
|
2026-05-09 15:38:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if combatable:
|
|
|
|
|
$DreamerBody/Body/ArmPivot.rotation.z = player_position.angle_to_point(get_viewport().get_mouse_position())
|
|
|
|
|
$HitCollision.rotation.y = -$DreamerBody/Body/ArmPivot.rotation.z + face_rotation
|
2026-05-08 16:33:09 +00:00
|
|
|
|
2026-05-09 15:38:52 +00:00
|
|
|
if ($DreamerBody/Body/ArmPivot.rotation_degrees.z < -90) or ($DreamerBody/Body/ArmPivot.rotation_degrees.z > 90):
|
|
|
|
|
face_left = true
|
|
|
|
|
$DreamerBody/Body/ArmPivot.scale.y = -1
|
|
|
|
|
$DreamerBody/Body/ArmPivot.scale.x = -1
|
|
|
|
|
var mouse_pos = get_viewport().get_mouse_position()
|
|
|
|
|
mouse_pos.y = (viewport_half.y) + ((viewport_half.y) - mouse_pos.y)
|
|
|
|
|
|
|
|
|
|
$DreamerBody/Body/ArmPivot.rotation.z = viewport_half.angle_to_point(mouse_pos)
|
|
|
|
|
else:
|
|
|
|
|
face_left = false
|
|
|
|
|
$DreamerBody/Body/ArmPivot.scale.y = 1
|
|
|
|
|
$DreamerBody/Body/ArmPivot.scale.x = 1
|
|
|
|
|
else:
|
|
|
|
|
$DreamerBody/Body/ArmPivot.global_rotation.y = face_rotation
|
|
|
|
|
$DreamerBody/Body/ArmPivot.scale.y = 1
|
|
|
|
|
$DreamerBody/Body/ArmPivot.scale.x = 1
|
|
|
|
|
$DreamerBody/Body/ArmPivot.rotation.z = 0
|
2026-05-08 16:33:09 +00:00
|
|
|
|
2026-05-08 14:22:54 +00:00
|
|
|
if Input.is_action_pressed("jump") and is_on_floor():
|
|
|
|
|
velocity.y = JUMP_VELOCITY
|
|
|
|
|
$DreamerBody/Animator.set("parameters/jump/request", AnimationNodeOneShot.ONE_SHOT_REQUEST_FIRE)
|
|
|
|
|
|
|
|
|
|
var input_dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
2026-05-09 15:38:52 +00:00
|
|
|
if not combatable:
|
|
|
|
|
if input_dir.x > 0:
|
|
|
|
|
face_left = false
|
|
|
|
|
if input_dir.x < 0:
|
|
|
|
|
face_left = true
|
|
|
|
|
|
|
|
|
|
if Input.is_action_just_pressed("attack"):
|
|
|
|
|
$DreamerBody/Body/ArmPivot/Slash.play("default")
|
|
|
|
|
var hits = $HitCollision.get_overlapping_bodies()
|
|
|
|
|
|
|
|
|
|
for body in hits:
|
2026-05-09 17:18:11 +00:00
|
|
|
if body == self: continue
|
|
|
|
|
|
2026-05-09 15:38:52 +00:00
|
|
|
if "health" in body:
|
|
|
|
|
body.health -= 10
|
2026-05-09 17:18:11 +00:00
|
|
|
|
|
|
|
|
body.position.y += 0.2
|
|
|
|
|
body.velocity.y = 0.4
|
|
|
|
|
body.velocity += global_position.direction_to(body.global_position) * 5
|
|
|
|
|
|
|
|
|
|
if body.velocity.length() > 5:
|
|
|
|
|
body.velocity = body.velocity.normalized() * 5
|
|
|
|
|
|
|
|
|
|
if "mid_knockback" in body:
|
|
|
|
|
body.mid_knockback = true
|
|
|
|
|
|
|
|
|
|
if "on_knockback" in body:
|
|
|
|
|
body.on_knockback()
|
2026-05-08 16:33:09 +00:00
|
|
|
|
2026-05-08 17:52:45 +00:00
|
|
|
var direction = (camera.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
2026-05-09 18:16:23 +00:00
|
|
|
if direction and (knockback_time <= 0):
|
2026-05-08 14:22:54 +00:00
|
|
|
velocity.x = direction.x * SPEED
|
|
|
|
|
velocity.z = direction.z * SPEED
|
|
|
|
|
|
|
|
|
|
$DreamerBody/Animator.set("parameters/walk/blend_amount", abs(direction.length()))
|
|
|
|
|
else:
|
|
|
|
|
|
2026-05-09 18:16:23 +00:00
|
|
|
velocity.x = move_toward(velocity.x, 0, delta * 24)
|
|
|
|
|
velocity.z = move_toward(velocity.z, 0, delta * 24)
|
2026-05-08 14:22:54 +00:00
|
|
|
|
|
|
|
|
$DreamerBody/Animator.set("parameters/walk/blend_amount", 0)
|
|
|
|
|
|
|
|
|
|
if direction and is_on_floor():
|
|
|
|
|
walk_animation_time += delta * 25
|
|
|
|
|
|
2026-05-08 16:33:09 +00:00
|
|
|
$DreamerBody.position.y = sin(walk_animation_time + 1) / 16
|
2026-05-08 14:22:54 +00:00
|
|
|
$DreamerBody.rotation.z = sin(walk_animation_time / 2) / 16
|
|
|
|
|
else:
|
|
|
|
|
walk_animation_time = 0
|
|
|
|
|
|
|
|
|
|
$DreamerBody.rotation.z /= 1 + (delta * 2.5)
|
|
|
|
|
|
|
|
|
|
$DreamerBody.position.y /= 1 + (delta * 12)
|
|
|
|
|
|
|
|
|
|
if is_on_floor():
|
|
|
|
|
$DreamerBody/Animator.set("parameters/fall/blend_amount", 0)
|
2026-05-08 16:33:09 +00:00
|
|
|
$DreamerBody/Animator.set("parameters/leap/blend_amount", 0)
|
2026-05-08 14:22:54 +00:00
|
|
|
else:
|
2026-05-08 16:33:09 +00:00
|
|
|
if velocity.y < 0:
|
|
|
|
|
$DreamerBody/Animator.set("parameters/fall/blend_amount", 1)
|
|
|
|
|
$DreamerBody/Animator.set("parameters/leap/blend_amount", 0)
|
|
|
|
|
else:
|
|
|
|
|
$DreamerBody/Animator.set("parameters/fall/blend_amount", 0)
|
|
|
|
|
$DreamerBody/Animator.set("parameters/leap/blend_amount", 1)
|
2026-05-08 14:22:54 +00:00
|
|
|
|
|
|
|
|
move_and_slide()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$Shadow.global_position.y = $Floorcast.get_collision_point().y + 0.01
|
|
|
|
|
|