feat: Implement PlayerMovementManager for grid-based movement, collision, and a push mechanic with Stop n Go mode rules.

This commit is contained in:
Yogi Wiguna
2026-03-24 16:15:00 +08:00
parent f64eed0bfe
commit f7463d57cd
3 changed files with 32 additions and 47 deletions
+27 -2
View File
@@ -538,11 +538,36 @@ func _is_path_blocked_by_physics(from_grid: Vector2i, to_grid: Vector2i) -> bool
if not player.is_inside_tree(): return false
var space_state = player.get_world_3d().direct_space_state
# 1. Path check: Block movement if a wall exists between the current and target tile
var from_v3 = Vector3(from_grid.x + 0.5, 0.5, from_grid.y + 0.5)
var to_v3 = Vector3(to_grid.x + 0.5, 0.5, to_grid.y + 0.5)
# DIAGONAL Leniency: If moving diagonally, use two offset rays to 'squeeze' past corners
var is_diagonal = (from_grid.x != to_grid.x) and (from_grid.y != to_grid.y)
if is_diagonal and not player.get("is_invisible"):
var direction = (to_v3 - from_v3).normalized()
var perp = Vector3(-direction.z, 0, direction.x) * 0.2 # Offset by 20cm
# Ray 1: Offset left
var q1 = PhysicsRayQueryParameters3D.create(from_v3 + perp, to_v3 + perp)
q1.collide_with_bodies = true
var r1 = space_state.intersect_ray(q1)
# Ray 2: Offset right
var q2 = PhysicsRayQueryParameters3D.create(from_v3 - perp, to_v3 - perp)
q2.collide_with_bodies = true
var r2 = space_state.intersect_ray(q2)
# If BOTH rays hit something that isn't the player, it's blocked
# If only ONE hits, it might be a thin corner/wall we can skirt around
if r1 and r2:
if r1.collider != player and r2.collider != player:
return true
# Fall through to standard central ray check for extra safety?
# Or just return false if at least one passed. Let's do one more check.
# 1. Path check: Block movement if a wall exists between the current and target tile
var path_query = PhysicsRayQueryParameters3D.create(from_v3, to_v3)
path_query.collide_with_areas = false
path_query.collide_with_bodies = true