feat: Introduce PlayerMovementManager to manage player movement, rotation, attack mode push mechanics, and grid-based collision detection.

This commit is contained in:
Yogi Wiguna
2026-02-20 17:54:58 +08:00
parent e90cbfe246
commit 0e4d69f7b9
8 changed files with 193 additions and 61 deletions
+25 -13
View File
@@ -37,10 +37,16 @@ func rotate_towards_target(target_pos: Vector2i):
var direction = Vector3(target_pos.x - player.current_position.x, 0, target_pos.y - player.current_position.y)
if direction != Vector3.ZERO:
target_rotation = atan2(direction.x, direction.z)
# Sync rotation to other clients
if player.is_multiplayer_authority() and player.has_method("can_rpc") and player.can_rpc():
if player.is_multiplayer_authority() and _can_rpc():
player.rpc("sync_rotation", target_rotation)
func _can_rpc() -> bool:
if not player or not player.is_inside_tree() or not player.multiplayer.has_multiplayer_peer():
return false
if player.multiplayer.multiplayer_peer.get_connection_status() != MultiplayerPeer.CONNECTION_CONNECTED:
return false
return true
func simple_move_to(grid_position: Vector2i) -> bool:
if is_moving:
var direction = grid_position - player.current_position
@@ -49,9 +55,11 @@ func simple_move_to(grid_position: Vector2i) -> bool:
return false
if not player.is_multiplayer_authority():
# print("[Move] Failed: Not authority for ", player.name)
return false
if player.get("is_frozen"):
print("[Move] Failed: Player is frozen")
return false
# Stop n Go Mode Violation Check
@@ -60,6 +68,7 @@ func simple_move_to(grid_position: Vector2i) -> bool:
var manager = main.get_node_or_null("StopNGoManager")
if manager and manager.has_method("check_movement_violation"):
if manager.check_movement_violation(player.name.to_int(), player.current_position, grid_position):
print("[Move] Failed: Stop N Go Violation")
return false
var distance: int
@@ -68,13 +77,12 @@ func simple_move_to(grid_position: Vector2i) -> bool:
else:
distance = abs(grid_position.x - player.current_position.x) + abs(grid_position.y - player.current_position.y)
if distance != 1:
return false # Only single-step moves allowed
if not enhanced_gridmap.is_position_valid(grid_position):
# print("[Move] Failed: Position not valid on GridMap %s" % grid_position)
return false
if player.has_method("can_move_to_finish") and not player.can_move_to_finish(grid_position):
print("[Move] Failed: Cannot move to finish yet")
return false
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(grid_position.x, 0, grid_position.y))
@@ -83,10 +91,12 @@ func simple_move_to(grid_position: Vector2i) -> bool:
var is_wall_passable = player.get("is_invisible") and cell_item == 4
if (cell_item == -1 or cell_item in enhanced_gridmap.non_walkable_items) and not is_wall_passable:
print("[Move] Failed: Cell Item %d is non-walkable" % cell_item)
return false
# PHYSICS CHECK: Ensure no static obstacles (like Stands) are blocking the path
if _is_position_blocked_by_physics(grid_position):
print("[Move] Failed: Blocked by physics raycast at %s" % grid_position)
return false
if player.is_position_occupied(grid_position):
@@ -110,7 +120,7 @@ func simple_move_to(grid_position: Vector2i) -> bool:
rotate_towards_target(grid_position)
if player.is_multiplayer_authority() and player.has_method("can_rpc") and player.can_rpc():
if player.is_multiplayer_authority() and _can_rpc():
if player.has_method("sync_walk_animation"):
player.rpc("sync_walk_animation")
@@ -119,7 +129,7 @@ func simple_move_to(grid_position: Vector2i) -> bool:
current_move_direction = grid_position - player.current_position
if player.is_multiplayer_authority() and player.has_method("can_rpc") and player.can_rpc():
if player.is_multiplayer_authority() and _can_rpc():
player.rpc("start_movement_along_path", path, not (player.is_bot or player.is_in_group("Bots")))
return true
@@ -151,7 +161,7 @@ func try_push(target_pos: Vector2i, direction: Vector2i) -> bool:
# 1. Drop Victim's Tiles
if other_player.has_method("drop_all_tiles"):
if player.has_method("can_rpc") and player.can_rpc():
if _can_rpc():
other_player.rpc("drop_all_tiles") # Sync drop
# 2. Spawn PowerUps around Victim
@@ -169,17 +179,17 @@ func try_push(target_pos: Vector2i, direction: Vector2i) -> bool:
not _is_position_blocked_by_physics(pushed_to_pos):
# Valid push
var push_path = [Vector2(pushed_to_pos.x, pushed_to_pos.y)]
if player.has_method("can_rpc") and player.can_rpc():
if _can_rpc():
other_player.rpc("start_movement_along_path", push_path, false)
other_player.target_position = pushed_to_pos # Logical update
# Apply stun/freeze effect as requested (same as wall stagger)
if player.has_method("can_rpc") and player.can_rpc():
if _can_rpc():
other_player.rpc("apply_stagger", 1.5)
else:
# Wall/Blocked -> Stagger in place
if player.has_method("can_rpc") and player.can_rpc():
if _can_rpc():
other_player.rpc("apply_stagger", 1.5)
# 4. Consume Boost (Full) - One hit per charge
@@ -453,7 +463,9 @@ func _is_position_blocked_by_physics(target_pos: Vector2i) -> bool:
var result = space_state.intersect_ray(query)
if result:
if result.collider != player:
# print("Movement Blocked by Physics Body: ", result.collider.name)
return true
# ONLY block if it's a Static Tekton Stand
# Ignore GridMap floors/walls, which are handled by get_cell_item rules
if result.collider.name.find("StaticTektonStand") != -1 or result.collider.is_in_group("StaticTektonStands") or result.collider.has_method("is_stand"):
return true
return false