Entity movement improvements

This commit is contained in:
2026-06-11 23:03:11 -05:00
parent 5f52b20400
commit c7b0d79d06
2 changed files with 8 additions and 11 deletions
+1
View File
@@ -27,6 +27,7 @@ size = Vector3(1.3, 1.3, 1.3)
[node name="Entity" type="CharacterBody3D"] [node name="Entity" type="CharacterBody3D"]
collision_layer = 2 collision_layer = 2
collision_mask = 3
script = ExtResource("1_8e8ef") script = ExtResource("1_8e8ef")
entityId = "35ce980f-3df9-4e09-b365-1a228948cf78" entityId = "35ce980f-3df9-4e09-b365-1a228948cf78"
metadata/_custom_type_script = "uid://c8146flooxeue" metadata/_custom_type_script = "uid://c8146flooxeue"
+7 -11
View File
@@ -2,17 +2,13 @@ class_name EntityMovement extends Node
const GRAVITY = Vector3.DOWN * 100 const GRAVITY = Vector3.DOWN * 100
const FRICTION = 0.01 const FRICTION = 0.01
const WALK_SPEED_DEFAULT = 8 const SPEED_DEFAULT = 8
const RUN_SPEED_DEFAULT = 12 const ROTATION_SPEED_DEFAULT = 15.0
# var _inputDir:Vector2 = Vector2.ZERO
# var _running:bool = false
@export var entity:Entity @export var entity:Entity
@export var interactingArea:EntityInteractingArea @export var interactingArea:EntityInteractingArea
# @export var rotate:Node3D @export var speed:float = SPEED_DEFAULT
@export var walkSpeed:float = WALK_SPEED_DEFAULT @export var rotationSpeed:float = ROTATION_SPEED_DEFAULT
# @export var runSpeed:float = RUN_SPEED_DEFAULT
# #
# Private Methods # Private Methods
@@ -21,7 +17,7 @@ func _applyGravity() -> void:
if !entity.is_on_floor(): if !entity.is_on_floor():
entity.velocity += GRAVITY * get_process_delta_time() entity.velocity += GRAVITY * get_process_delta_time()
func _applyPlayerMovement(_delta:float): func _applyPlayerMovement(delta:float):
# Interactions, may move # Interactions, may move
if Input.is_action_just_pressed("interact") && interactingArea && interactingArea.hasInteraction(): if Input.is_action_just_pressed("interact") && interactingArea && interactingArea.hasInteraction():
interactingArea.interact() interactingArea.interact()
@@ -48,9 +44,9 @@ func _applyPlayerMovement(_delta:float):
if directionAdjusted.length() <= 0.01: if directionAdjusted.length() <= 0.01:
return return
entity.look_at(entity.global_position + directionAdjusted, Vector3.UP) var targetYaw:float = atan2(-directionAdjusted.x, -directionAdjusted.z)
entity.rotation.y = lerp_angle(entity.rotation.y, targetYaw, rotationSpeed * delta)
var speed = walkSpeed
entity.velocity.x = directionAdjusted.x * speed entity.velocity.x = directionAdjusted.x * speed
entity.velocity.z = directionAdjusted.z * speed entity.velocity.z = directionAdjusted.z * speed