Just making things work again
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
				
			|||||||
 | 
					@tool
 | 
				
			||||||
class_name EntityMovement extends Node
 | 
					class_name EntityMovement extends Node
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const SPEED = 64.0
 | 
					 | 
				
			||||||
const FRICTION = 0.01
 | 
					const FRICTION = 0.01
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum FacingDirection {
 | 
					enum FacingDirection {
 | 
				
			||||||
@@ -24,61 +24,65 @@ const FacingDirAngle = {
 | 
				
			|||||||
	FacingDirection.WEST: -PI / 2
 | 
						FacingDirection.WEST: -PI / 2
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var _inputDir:Vector2 = Vector2.ZERO
 | 
				
			||||||
 | 
					var _facingDir:FacingDirection = FacingDirection.SOUTH
 | 
				
			||||||
 | 
					var _running:bool = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@export var body:CharacterBody3D
 | 
					@export var body:CharacterBody3D
 | 
				
			||||||
@export var rotate:Node3D
 | 
					@export var rotate:Node3D
 | 
				
			||||||
@export var sprite:AnimatedSprite3D
 | 
					@export var sprite:AnimatedSprite3D
 | 
				
			||||||
 | 
					@export var walkSpeed:float = 48.0
 | 
				
			||||||
 | 
					@export var runSpeed:float = 64.0
 | 
				
			||||||
 | 
					@export var facingDir:FacingDirection = FacingDirection.SOUTH:
 | 
				
			||||||
 | 
						set(value):
 | 
				
			||||||
 | 
							_facingDir = value
 | 
				
			||||||
 | 
							_updateSprite()
 | 
				
			||||||
 | 
						get:
 | 
				
			||||||
 | 
							return _facingDir
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var facingDir:FacingDirection = FacingDirection.SOUTH
 | 
					#
 | 
				
			||||||
var inputDir:Vector2 = Vector2.ZERO
 | 
					# Private Methods
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
func _enter_tree() -> void:
 | 
					func _updateSprite() -> void:
 | 
				
			||||||
	if !sprite:
 | 
						if !sprite || sprite.animation == FacingDirWalkAnimations[facingDir]:
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	for dir in FacingDirWalkAnimations:
 | 
						sprite.animation = FacingDirWalkAnimations[facingDir]
 | 
				
			||||||
		if sprite.animation != FacingDirWalkAnimations[dir]:
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		facingDir = dir
 | 
					 | 
				
			||||||
		break
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
func canMove() -> bool:
 | 
					 | 
				
			||||||
	return true
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
func applyFacingDir() -> void:
 | 
					func _applyFacingDir() -> void:
 | 
				
			||||||
	if !sprite || inputDir.length() <= 0.01:
 | 
						if !sprite || _inputDir.length() <= 0.01:
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if inputDir.y > 0:
 | 
						if _inputDir.y > 0:
 | 
				
			||||||
		if facingDir != FacingDirection.NORTH && inputDir.x != 0:
 | 
							if facingDir != FacingDirection.NORTH && _inputDir.x != 0:
 | 
				
			||||||
			if inputDir.x > 0 && facingDir == FacingDirection.EAST:
 | 
								if _inputDir.x > 0 && facingDir == FacingDirection.EAST:
 | 
				
			||||||
				facingDir = FacingDirection.EAST
 | 
									facingDir = FacingDirection.EAST
 | 
				
			||||||
			elif inputDir.x < 0 && facingDir == FacingDirection.WEST:
 | 
								elif _inputDir.x < 0 && facingDir == FacingDirection.WEST:
 | 
				
			||||||
				facingDir = FacingDirection.WEST
 | 
									facingDir = FacingDirection.WEST
 | 
				
			||||||
			else:
 | 
								else:
 | 
				
			||||||
				facingDir = FacingDirection.NORTH
 | 
									facingDir = FacingDirection.NORTH
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			facingDir = FacingDirection.NORTH
 | 
								facingDir = FacingDirection.NORTH
 | 
				
			||||||
	elif inputDir.y < 0:
 | 
						elif _inputDir.y < 0:
 | 
				
			||||||
		if facingDir != FacingDirection.SOUTH && inputDir.x != 0:
 | 
							if facingDir != FacingDirection.SOUTH && _inputDir.x != 0:
 | 
				
			||||||
			if inputDir.x > 0 && facingDir == FacingDirection.EAST:
 | 
								if _inputDir.x > 0 && facingDir == FacingDirection.EAST:
 | 
				
			||||||
				facingDir = FacingDirection.EAST
 | 
									facingDir = FacingDirection.EAST
 | 
				
			||||||
			elif inputDir.x < 0 && facingDir == FacingDirection.WEST:
 | 
								elif _inputDir.x < 0 && facingDir == FacingDirection.WEST:
 | 
				
			||||||
				facingDir = FacingDirection.WEST
 | 
									facingDir = FacingDirection.WEST
 | 
				
			||||||
			else:
 | 
								else:
 | 
				
			||||||
				facingDir = FacingDirection.SOUTH
 | 
									facingDir = FacingDirection.SOUTH
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			facingDir = FacingDirection.SOUTH
 | 
								facingDir = FacingDirection.SOUTH
 | 
				
			||||||
	elif inputDir.x > 0:
 | 
						elif _inputDir.x > 0:
 | 
				
			||||||
		facingDir = FacingDirection.EAST
 | 
							facingDir = FacingDirection.EAST
 | 
				
			||||||
	else:
 | 
						else:
 | 
				
			||||||
		facingDir = FacingDirection.WEST
 | 
							facingDir = FacingDirection.WEST
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sprite.animation = FacingDirWalkAnimations[facingDir]
 | 
					func _applyGravity() -> void:
 | 
				
			||||||
 | 
					 | 
				
			||||||
func applyGravity() -> void:
 | 
					 | 
				
			||||||
	if !body.is_on_floor():
 | 
						if !body.is_on_floor():
 | 
				
			||||||
		body.velocity += PHYSICS.GRAVITY * get_process_delta_time()
 | 
							body.velocity += PHYSICS.GRAVITY * get_process_delta_time()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func applyMovement() -> void:
 | 
					func _applyMovement() -> void:
 | 
				
			||||||
	if !canMove():
 | 
						if !canMove():
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -98,7 +102,7 @@ func applyMovement() -> void:
 | 
				
			|||||||
	right = right.normalized()
 | 
						right = right.normalized()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var directionAdjusted = (
 | 
						var directionAdjusted = (
 | 
				
			||||||
		forward * inputDir.y + right * inputDir.x
 | 
							forward * _inputDir.y + right * _inputDir.x
 | 
				
			||||||
	).normalized()
 | 
						).normalized()
 | 
				
			||||||
	if directionAdjusted.length() <= 0.01:
 | 
						if directionAdjusted.length() <= 0.01:
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
@@ -107,19 +111,38 @@ func applyMovement() -> void:
 | 
				
			|||||||
		var targetRot = atan2(directionAdjusted.x, directionAdjusted.z)
 | 
							var targetRot = atan2(directionAdjusted.x, directionAdjusted.z)
 | 
				
			||||||
		rotate.rotation.y = targetRot
 | 
							rotate.rotation.y = targetRot
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	body.velocity.x = directionAdjusted.x * SPEED
 | 
						var speed = walkSpeed
 | 
				
			||||||
	body.velocity.z = directionAdjusted.z * SPEED
 | 
						if _running:
 | 
				
			||||||
 | 
							speed = runSpeed
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						body.velocity.x = directionAdjusted.x * speed
 | 
				
			||||||
 | 
						body.velocity.z = directionAdjusted.z * speed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func applyFriction(delta:float) -> void:
 | 
					func _applyFriction(delta:float) -> void:
 | 
				
			||||||
	body.velocity.x *= delta * FRICTION
 | 
						body.velocity.x *= delta * FRICTION
 | 
				
			||||||
	body.velocity.z *= delta * FRICTION
 | 
						body.velocity.z *= delta * FRICTION
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Protected Methods	
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					func canMove() -> bool:
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Callbacks
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					func _enter_tree() -> void:
 | 
				
			||||||
 | 
						_updateSprite()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _physics_process(delta:float) -> void:
 | 
					func _physics_process(delta:float) -> void:
 | 
				
			||||||
 | 
						if Engine.is_editor_hint():
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !body:
 | 
						if !body:
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	applyGravity()
 | 
						_applyGravity()
 | 
				
			||||||
	applyFriction(delta)
 | 
						_applyFriction(delta)
 | 
				
			||||||
	applyMovement()
 | 
						_applyMovement()
 | 
				
			||||||
	applyFacingDir()
 | 
						_applyFacingDir()
 | 
				
			||||||
	body.move_and_slide()
 | 
						body.move_and_slide()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1 +1,2 @@
 | 
				
			|||||||
class_name NPCMovement extends "res://entities/EntityMovement.gd"
 | 
					@tool
 | 
				
			||||||
 | 
					class_name NPCMovement extends "res://entity/EntityMovement.gd"
 | 
				
			||||||
@@ -1 +1,31 @@
 | 
				
			|||||||
 | 
					@tool
 | 
				
			||||||
class_name Player extends CharacterBody3D
 | 
					class_name Player extends CharacterBody3D
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@export var _movement:PlayerMovement
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@export var facingDirection:EntityMovement.FacingDirection:
 | 
				
			||||||
 | 
						set(value):
 | 
				
			||||||
 | 
							if _movement:
 | 
				
			||||||
 | 
								_movement.facingDir = value
 | 
				
			||||||
 | 
						get:
 | 
				
			||||||
 | 
							if _movement:
 | 
				
			||||||
 | 
								return _movement.facingDir
 | 
				
			||||||
 | 
							return EntityMovement.FacingDirection.SOUTH
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@export var walkSpeed:float = 48.0:
 | 
				
			||||||
 | 
						set(value):
 | 
				
			||||||
 | 
							if _movement:
 | 
				
			||||||
 | 
								_movement.walkSpeed = value
 | 
				
			||||||
 | 
						get:
 | 
				
			||||||
 | 
							if _movement:
 | 
				
			||||||
 | 
								return _movement.walkSpeed
 | 
				
			||||||
 | 
							return 48.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@export var runSpeed:float = 64.0:
 | 
				
			||||||
 | 
						set(value):
 | 
				
			||||||
 | 
							if _movement:
 | 
				
			||||||
 | 
								_movement.runSpeed = value
 | 
				
			||||||
 | 
						get:
 | 
				
			||||||
 | 
							if _movement:
 | 
				
			||||||
 | 
								return _movement.runSpeed
 | 
				
			||||||
 | 
							return 64.0
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,8 +64,9 @@ animations = [{
 | 
				
			|||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_g13of"]
 | 
					[sub_resource type="BoxShape3D" id="BoxShape3D_g13of"]
 | 
				
			||||||
size = Vector3(10, 16, 8)
 | 
					size = Vector3(10, 16, 8)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="Player" type="CharacterBody3D"]
 | 
					[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("_movement")]
 | 
				
			||||||
script = ExtResource("1_24gqh")
 | 
					script = ExtResource("1_24gqh")
 | 
				
			||||||
 | 
					_movement = NodePath("Scripts/PlayerMovement")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="Scripts" type="Node" parent="."]
 | 
					[node name="Scripts" type="Node" parent="."]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,4 +10,4 @@ func _process(delta: float) -> void:
 | 
				
			|||||||
	if Input.is_action_just_pressed("interact"):
 | 
						if Input.is_action_just_pressed("interact"):
 | 
				
			||||||
		interaction.interact()
 | 
							interaction.interact()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	movement.inputDir = Input.get_vector("move_left", "move_right", "move_back", "move_forward").normalized()
 | 
						movement._inputDir = Input.get_vector("move_left", "move_right", "move_back", "move_forward").normalized()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,5 @@
 | 
				
			|||||||
class_name PlayerMovement extends "res://entities/EntityMovement.gd"
 | 
					@tool
 | 
				
			||||||
 | 
					class_name PlayerMovement extends "res://entity/EntityMovement.gd"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func canMove() -> bool:
 | 
					func canMove() -> bool:
 | 
				
			||||||
	if PAUSE.isMovementPaused():
 | 
						if PAUSE.isMovementPaused():
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,6 +10,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[node name="Player" parent="." instance=ExtResource("2_0d2qr")]
 | 
					[node name="Player" parent="." instance=ExtResource("2_0d2qr")]
 | 
				
			||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 14.3947, 1.94879, -13.1025)
 | 
					transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 14.3947, 1.94879, -13.1025)
 | 
				
			||||||
 | 
					facingDirection = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="NPC" parent="." instance=ExtResource("3_0vfw4")]
 | 
					[node name="NPC" parent="." instance=ExtResource("3_0vfw4")]
 | 
				
			||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.30029, 4.06806, 0.563562)
 | 
					transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.30029, 4.06806, 0.563562)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,6 +11,7 @@ func _exit_tree() -> void:
 | 
				
			|||||||
	push_error("RootScene should not be removed from the scene tree. This is a bug.")
 | 
						push_error("RootScene should not be removed from the scene tree. This is a bug.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func onSceneChange(newScene:SceneSingleton.SceneType) -> void:
 | 
					func onSceneChange(newScene:SceneSingleton.SceneType) -> void:
 | 
				
			||||||
 | 
						print("overworld", overworld)
 | 
				
			||||||
	remove_child(overworld)
 | 
						remove_child(overworld)
 | 
				
			||||||
	remove_child(initial)
 | 
						remove_child(initial)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,7 @@ func _exit_tree() -> void:
 | 
				
			|||||||
	TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
 | 
						TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
 | 
				
			||||||
	TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
 | 
						TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _process(delta:float) -> void:
 | 
					func _process(_delta:float) -> void:
 | 
				
			||||||
	if(!isMapChanging()):
 | 
						if(!isMapChanging()):
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,7 @@ func _parseAdvancedText() -> void:
 | 
				
			|||||||
		key = tr(key)
 | 
							key = tr(key)
 | 
				
			||||||
	self.text = processInputTags(key)
 | 
						self.text = processInputTags(key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func processInputTags(text:String) -> String:
 | 
					func processInputTags(_text:String) -> String:
 | 
				
			||||||
	var regex = RegEx.new()
 | 
						var regex = RegEx.new()
 | 
				
			||||||
	regex.compile(r"\[input action=(.*?)\](.*?)\[/input\]")
 | 
						regex.compile(r"\[input action=(.*?)\](.*?)\[/input\]")
 | 
				
			||||||
	var result = text
 | 
						var result = text
 | 
				
			||||||
@@ -41,4 +41,4 @@ func processInputTags(text:String) -> String:
 | 
				
			|||||||
		# var icon_path = get_icon_for_action(action, device)
 | 
							# var icon_path = get_icon_for_action(action, device)
 | 
				
			||||||
		var img_tag = "[img height=%d valign=center,center]res://textures/input/%s.tres[/img]" % [ height, action ]
 | 
							var img_tag = "[img height=%d valign=center,center]res://textures/input/%s.tres[/img]" % [ height, action ]
 | 
				
			||||||
		result = result.replace(match.get_string(0), img_tag)
 | 
							result = result.replace(match.get_string(0), img_tag)
 | 
				
			||||||
	return result
 | 
						return result
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user