fix the instance of player

This commit is contained in:
2025-03-03 14:22:27 +08:00
parent 276aa439ab
commit 23e2e50c0c
2 changed files with 308 additions and 35 deletions
+25 -7
View File
@@ -6,6 +6,7 @@ extends Node3D
var enhanced_gridmap: EnhancedGridMap
@export var current_position: Vector2i
var is_player_moving: bool = false
var _verify_timer: float = 0.0
@export var cell_size: Vector3 = Vector3(2, 2, 2)
@export var cell_offset: Vector3 = Vector3(0, 0, 0)
@@ -58,11 +59,10 @@ func _ready():
if main_scene:
enhanced_gridmap = main_scene.get_node("EnhancedGridMap")
# Initialize behavior tree for bots
var behavior_tree = $BehaviorTree
# Early setup for bots
if is_bot == true or is_in_group("Bots"):
# Initialize behavior tree for bots
var behavior_tree = $BehaviorTree
# Disable all input processing for bots immediately
set_process_input(false)
set_process_unhandled_input(false)
@@ -135,6 +135,24 @@ func sync_bot_status(is_bot_status: bool):
behavior_tree.set_physics_process(false)
behavior_tree.set_process(false)
func _process(delta):
if is_multiplayer_authority():
# Visual debugging - show connection status in name label
$Name.text = str(name) + "\n(Auth: " + str(get_multiplayer_authority()) + ")"
# Periodically verify our existence to others
_verify_timer += delta
if _verify_timer >= 3.0:
_verify_timer = 0.0
rpc("ping_existence")
@rpc("any_peer", "call_local")
func ping_existence():
# This just lets other clients know this player exists
# They can check if they have this node
pass
func _physics_process(_delta):
if is_multiplayer_authority():
rpc("remote_set_position", global_position)
@@ -1065,11 +1083,11 @@ func update_visual_position():
rpc("sync_position", current_position)
@rpc("any_peer", "call_local")
func sync_position(pos: Vector2):
func sync_position(pos: Vector2i):
current_position = pos
# Ensure proper grid-aligned positioning
# Always update the visual position after position sync
global_position = Vector3(
current_position.x * cell_size.x + cell_size.x * 0.5,
1.0,
cell_size.y,
current_position.y * cell_size.z + cell_size.z * 0.5
)
) + cell_offset