More options to unstick if on two surfaces.

This commit is contained in:
SnekInAScarf 2026-11-16 12:35:03 -08:00
parent 902ed33ee4
commit 1a7a43ab52

View file

@ -83,6 +83,7 @@ const BRIDGE_FRAME = 10 # Wall to wall. Drawn upright, so it's turned a quarter.
const BRIDGE_VERTICAL_FRAME = 11 # Floor to ceiling.
const BRIDGE_GAP = 32.0 # One tile.
const BRIDGE_GAP_TOLERANCE = 1.5
const IN_AIR_FRAME = 8 # The InAir animation's frame.
###############
## Variables ##
@ -152,6 +153,7 @@ var isBridging := false
var bridgeAxis := Vector2.RIGHT # RIGHT between walls, DOWN between floor and ceiling.
var bridgeHoldSide := 0.0 # Which way along bridgeAxis we're holding (1, -1), or 0.
var timeSpentLeavingBridge := 0.0
var timeSpentDroppingFromBridge := 0.0
var carriedItem: CarryItem = null # The item riding in our center, or null. Tubes drop it.
@ -630,6 +632,7 @@ func _begin_bridge(normal: Vector2, ownPoint: Vector2, otherPoint: Vector2) -> v
timeSpentHoldingUpOnFloor = 0.0
timeSpentHoldingEdge = 0.0
timeSpentLeavingBridge = 0.0
timeSpentDroppingFromBridge = 0.0
# We're still holding away from the surface we left, towards the one across.
# Keep holding and we cross over to it after HOLD_TIME, like any other hold.
bridgeHoldSide = signf(normal.dot(bridgeAxis))
@ -652,24 +655,54 @@ func _begin_bridge(normal: Vector2, ownPoint: Vector2, otherPoint: Vector2) -> v
# Holding towards either surface for HOLD_TIME sticks us to it and lets go of
# the other: left or right between walls, up or down between floor and ceiling.
# Holding down between walls, or left or right between floor and ceiling, for
# HOLD_TIME lets go of both and drops us. Diagonals do neither.
func _update_bridge(delta: float, moveInput: Vector2) -> void:
velocity = Vector2.ZERO
var inputDirection := Vector2(moveInput.x, -moveInput.y) # Up is negative y.
var side := signf(inputDirection.dot(bridgeAxis))
var along := signf(inputDirection.dot(bridgeAxis))
var across := signf(inputDirection.dot(bridgeAxis.orthogonal()))
var side := along if across == 0.0 else 0.0
if side != 0.0 and side == bridgeHoldSide:
timeSpentLeavingBridge += delta
else:
timeSpentLeavingBridge = 0.0
bridgeHoldSide = side
# Between walls only down drops us (bridgeAxis.orthogonal() is up there).
var holdingToDrop := along == 0.0 and across != 0.0
if bridgeAxis == Vector2.RIGHT:
holdingToDrop = holdingToDrop and inputDirection.y > 0.0
if holdingToDrop:
timeSpentDroppingFromBridge += delta
else:
timeSpentDroppingFromBridge = 0.0
if timeSpentLeavingBridge >= HOLD_TIME:
_leave_bridge(bridgeAxis * side, delta)
elif timeSpentDroppingFromBridge >= HOLD_TIME:
_drop_from_bridge()
# Lets go of both surfaces and falls from where we are.
func _drop_from_bridge() -> void:
isBridging = false
timeSpentLeavingBridge = 0.0
timeSpentDroppingFromBridge = 0.0
velocity = Vector2.ZERO
# is_on_floor() and friends still describe where we bridged from. A move on
# the spot brings them up to date, so we don't count as on it.
move_and_slide()
_set_sprite_rotation(0.0)
_show_pose(&"InAir", IN_AIR_FRAME)
# Sticks to the surface in `direction` from us.
func _leave_bridge(direction: Vector2, delta: float) -> void:
isBridging = false
timeSpentLeavingBridge = 0.0
timeSpentDroppingFromBridge = 0.0
var normal := -direction
var gap := BRIDGE_GAP / 2.0 - _get_radius()
_set_sprite_rotation(_rotation_for(normal))