update logic for push
This commit is contained in:
@@ -326,8 +326,9 @@ func _try_move() -> bool:
|
||||
return false
|
||||
|
||||
# Redundant safety check (simple_move_to also checks this)
|
||||
if actor.is_position_occupied(next_step):
|
||||
return false
|
||||
# Removed to allow PUSHING mechanics (simple_move_to handles occupancy/pushing)
|
||||
# if actor.is_position_occupied(next_step):
|
||||
# return false
|
||||
|
||||
# Execute SINGLE STEP movement using player manager
|
||||
if actor.movement_manager.simple_move_to(next_step):
|
||||
|
||||
@@ -46,10 +46,6 @@ func simple_move_to(grid_position: Vector2i) -> bool:
|
||||
var direction = grid_position - player.current_position
|
||||
|
||||
# FIX: Only buffer if direction is DIFFERENT from current move (prevents overshoot)
|
||||
# We need to know current move direction. We can infer it or store it.
|
||||
# For now, let's assume if we are moving, we don't buffer same direction.
|
||||
# But we need to know what the current direction is.
|
||||
# Let's add a variable `current_move_direction` to the class first.
|
||||
if direction != current_move_direction:
|
||||
buffer_move_input(direction)
|
||||
return false
|
||||
@@ -81,9 +77,17 @@ func simple_move_to(grid_position: Vector2i) -> bool:
|
||||
|
||||
# Check walkability and obstacles
|
||||
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(grid_position.x, 0, grid_position.y))
|
||||
if cell_item == -1 or cell_item in enhanced_gridmap.non_walkable_items or player.is_position_occupied(grid_position):
|
||||
if cell_item == -1 or cell_item in enhanced_gridmap.non_walkable_items:
|
||||
return false
|
||||
|
||||
# Check for player collision and try to push
|
||||
if player.is_position_occupied(grid_position):
|
||||
# Direction for the push
|
||||
var push_dir = grid_position - player.current_position
|
||||
if not try_push(grid_position, push_dir):
|
||||
return false
|
||||
# If push succeeded, the tile is now technically free (or will be processed as free)
|
||||
# proceed to move into it
|
||||
|
||||
# All checks passed, perform move
|
||||
rotate_towards_target(grid_position)
|
||||
@@ -97,12 +101,103 @@ func simple_move_to(grid_position: Vector2i) -> bool:
|
||||
|
||||
current_move_direction = grid_position - player.current_position
|
||||
|
||||
# Use the existing RPC to move (assuming player still has this RPC or we move it here)
|
||||
# For now, we'll call the player's RPC method
|
||||
# Use the existing RPC to move
|
||||
player.rpc("start_movement_along_path", path, not (player.is_bot or player.is_in_group("Bots")))
|
||||
|
||||
return true
|
||||
|
||||
func try_push(target_pos: Vector2i, direction: Vector2i) -> bool:
|
||||
if not player.has_method("get_player_at_position"):
|
||||
return false
|
||||
|
||||
var other_player = player.get_player_at_position(target_pos)
|
||||
if not other_player:
|
||||
return false # Should be occupied if we called this, but safety check
|
||||
|
||||
# Calculate where they will be pushed to
|
||||
var pushed_to_pos = target_pos + direction
|
||||
|
||||
# Check if pushed destination is valid
|
||||
if not enhanced_gridmap.is_position_valid(pushed_to_pos):
|
||||
return false
|
||||
|
||||
# Check walkability of pushed destination
|
||||
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(pushed_to_pos.x, 0, pushed_to_pos.y))
|
||||
if cell_item == -1 or cell_item in enhanced_gridmap.non_walkable_items:
|
||||
return false
|
||||
|
||||
# Check if pushed destination is ALREADY occupied (no daisy chaining)
|
||||
if player.is_position_occupied(pushed_to_pos):
|
||||
return false
|
||||
|
||||
# Check if other player is currently moving (don't push moving players to avoid sync issues)
|
||||
if other_player.is_player_moving:
|
||||
return false
|
||||
|
||||
# EXECUTE PUSH
|
||||
print("Player %s PUSHING %s to %s" % [player.name, other_player.name, pushed_to_pos])
|
||||
|
||||
# Force move the other player
|
||||
# We use rpc to sync this change. Since we are authority, we can dictate pos.
|
||||
|
||||
# 1. Update their position variable immediately so our move check passes next frame?
|
||||
# actually simple_move_to continues immediately.
|
||||
|
||||
# We need to forcefully animate/move them.
|
||||
# Let's use their own movement RPC if possible, or a special push RPC.
|
||||
# For simplicity, we'll assume they snap-move or use the standard path movement but faster?
|
||||
# Let's use the standard movement for now to ensure consistency.
|
||||
|
||||
var path = [Vector2(target_pos.x, target_pos.y), Vector2(pushed_to_pos.x, pushed_to_pos.y)]
|
||||
# path.pop_front() # start_movement_along_path expects full path?
|
||||
# Actually start_movement_along_path usually takes [start, end] or [end]?
|
||||
# Looking at simple_move_to above:
|
||||
# path = [current, target]
|
||||
# path.pop_front() -> path is [target]
|
||||
# So it expects just the waypoints excluding start.
|
||||
|
||||
var push_path = [Vector2(pushed_to_pos.x, pushed_to_pos.y)]
|
||||
|
||||
# Call RPC on the OTHER player
|
||||
other_player.rpc("start_movement_along_path", push_path, false) # false = no cam checks?
|
||||
# Wait, the boolean arg is "is_local_human"?
|
||||
# In player.gd call: player.rpc("start_movement_along_path", path, not (player.is_bot...))
|
||||
|
||||
# Update their current_position immediately so `is_position_occupied` returns false for us
|
||||
# (The RPC handles the visual tween, but we need logical update)
|
||||
# However, start_movement_along_path usually updates current_position at start or end?
|
||||
# If we don't update it now, our `player.is_position_occupied(grid_position)` check in subsequent frames might be ok,
|
||||
# but `simple_move_to` is synchronous-ish.
|
||||
|
||||
# Crucial: We need to make sure `player.is_position_occupied` returns false for `grid_position`
|
||||
# RIGHT NOW so we can return true and move into it.
|
||||
# But `is_position_occupied` checks `current_position` and `target_position`.
|
||||
# So we need to update `other_player`'s state.
|
||||
|
||||
other_player.target_position = pushed_to_pos
|
||||
other_player.is_player_moving = true # Mark them as moving so they occupy the NEW spot vs OLD spot?
|
||||
# Actually is_position_occupied checks BOTH current and target.
|
||||
# So if they are moving, they occupy BOTH until finished?
|
||||
# See player.gd:
|
||||
# if player.is_player_moving and player.target_position == pos: return true
|
||||
# if player.current_position == pos: return true
|
||||
|
||||
# This implies a moving player blocks 2 tiles.
|
||||
# If we want to move into `target_pos`, `other_player` must NOT count as occupying it.
|
||||
# But they ARE at `target_pos`.
|
||||
# We physically can't be at the same spot.
|
||||
# So we essentially need them to VACATE `target_pos` logically.
|
||||
|
||||
# Hack/Fix: We manually update their `current_position` to `pushed_to_pos` immediately?
|
||||
# No, that breaks visual interpolation.
|
||||
|
||||
# Solution: The push logic implies simultaneity or high speed.
|
||||
# If we assume the push is instant-ish logic:
|
||||
# We update valid logical positions. Visuals catch up.
|
||||
|
||||
return true
|
||||
|
||||
|
||||
func buffer_move_input(direction: Vector2i):
|
||||
buffered_direction = direction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user