Stop at ledges with the leading edge sensor at the edge
The slime used to stop with its center on the corner, leaving the flat side of the sprite floating past the edge. It now stops with the leading sensor just past the edge, so the sprite's side lines up with it. Holding on then detaches, and pressing into the surface wraps from there. Wall tops now stop the same way, instead of carrying straight on into the wrap, and walls show the ReachX animation while held at an edge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e6aaf57ec6
commit
acd25f9909
1 changed files with 13 additions and 15 deletions
|
|
@ -31,6 +31,9 @@ const HOLD_TIME = 0.5
|
|||
const EDGE_SENSOR_RANGE := 12.0
|
||||
const EDGE_SENSOR_DEPTH = 4.0 # How far past our radius the sensors reach into the surface.
|
||||
const WRAP_MARGIN = 0.5 # Extra gap from the corner so we don't clip into it.
|
||||
# Where we stop short of an edge, from our center: with the leading sensor just
|
||||
# past it, so the sprite's side lines up with the edge and the sensor reads "no surface".
|
||||
const EDGE_STOP_DISTANCE = EDGE_SENSOR_RANGE - 0.5
|
||||
|
||||
const HOP_REACH = 32.0
|
||||
const HOP_NO_CEILING_HEIGHT = 16.0 # Floor hop with nothing in reach, so you can tell it worked.
|
||||
|
|
@ -177,13 +180,13 @@ func _update_facing(xInput: float, yInput: float) -> void:
|
|||
func _update_animation(xInput:float, yInput:float):
|
||||
if xInput and (isStickingToCeiling or is_on_floor()) and timeSpentHoldingEdge == 0:
|
||||
sprite.play("Moving")
|
||||
elif yInput and isStickingToWall:
|
||||
elif yInput and isStickingToWall and timeSpentHoldingEdge == 0:
|
||||
sprite.play("Moving")
|
||||
|
||||
elif !is_on_floor() and !isStickingToWall and !isStickingToCeiling:
|
||||
sprite.play("InAir")
|
||||
|
||||
elif (is_on_floor() or isStickingToCeiling) and timeSpentHoldingEdge > 0:
|
||||
elif _get_surface_normal() != Vector2.ZERO and timeSpentHoldingEdge > 0:
|
||||
sprite.play("ReachX")
|
||||
|
||||
elif ((is_on_floor() and timeSpentHoldingUpOnFloor > 0) or
|
||||
|
|
@ -458,7 +461,7 @@ func _find_edge_corner(normal: Vector2, direction: Vector2, reach: float) -> Var
|
|||
return corner
|
||||
|
||||
|
||||
# Stops us at an edge we'd cross this frame, until we've held towards it for HOLD_TIME.
|
||||
# Stops us with our leading sensor at an edge, until we've held towards it for HOLD_TIME.
|
||||
func _hold_at_edge(delta: float) -> void:
|
||||
var normal := _get_surface_normal()
|
||||
var tangent := normal.orthogonal()
|
||||
|
|
@ -468,17 +471,12 @@ func _hold_at_edge(delta: float) -> void:
|
|||
return
|
||||
|
||||
var direction := tangent * signf(speedAlongSurface)
|
||||
# Climbing past a wall's top swings over it instead (_start_wall_top_wrap).
|
||||
var onWall := absf(normal.x) > 0.5
|
||||
if onWall and direction.y < 0:
|
||||
return
|
||||
|
||||
var distanceThisFrame := absf(speedAlongSurface) * delta
|
||||
var corner = _find_edge_corner(normal, direction, distanceThisFrame + 1)
|
||||
var distanceToEdge := INF
|
||||
var corner = _find_edge_corner(normal, direction, EDGE_STOP_DISTANCE + distanceThisFrame + 1)
|
||||
var distanceToStop := INF
|
||||
if corner != null:
|
||||
distanceToEdge = (corner - global_position).dot(direction)
|
||||
if distanceToEdge > distanceThisFrame:
|
||||
distanceToStop = (corner - global_position).dot(direction) - EDGE_STOP_DISTANCE
|
||||
if distanceToStop > distanceThisFrame:
|
||||
timeSpentHoldingEdge = 0.0
|
||||
return
|
||||
|
||||
|
|
@ -486,9 +484,9 @@ func _hold_at_edge(delta: float) -> void:
|
|||
return
|
||||
timeSpentHoldingEdge += delta
|
||||
|
||||
# Set our speed along the surface to stop exactly at the edge.
|
||||
var speedToReachEdge := maxf(distanceToEdge, 0.0) / delta
|
||||
velocity += direction * (speedToReachEdge - absf(speedAlongSurface))
|
||||
# Set our speed along the surface to stop exactly on the spot.
|
||||
var speedToReachStop := maxf(distanceToStop, 0.0) / delta
|
||||
velocity += direction * (speedToReachStop - absf(speedAlongSurface))
|
||||
|
||||
# We've just climbed past a wall's top corner, so _find_edge_corner (which looks
|
||||
# from the surface we're on) can't see it. Find it with our own raycasts.
|
||||
|
|
|
|||
Loading…
Reference in a new issue