Compare commits

..

No commits in common. "e5bdc85293cd1a1592c1b474f1d616304c28e128" and "90186a6c2e9b105f9d69b8ee042377617d29f9ac" have entirely different histories.

View file

@ -22,7 +22,7 @@ const WALL_STICK_SPEED = 20.0 # Small push into the wall that keeps the slime pr
const SURFACE_SNAP_DISTANCE = 4.0 const SURFACE_SNAP_DISTANCE = 4.0
# How long to hold a direction before something happens: letting go of a wall # How long to hold a direction before something happens: letting go of a wall
# or ceiling (holding away from it), carrying on over an edge we're holding at, # or ceiling (holding away from it), carrying on over an edge we're holding at,
# and hopping. # hopping, and how long we hang on a lip.
const HOLD_TIME = 0.5 const HOLD_TIME = 0.5
var isStickingToWall := false var isStickingToWall := false
@ -68,6 +68,15 @@ var wrapOntoNormal := Vector2.UP # Normal of the surface we end up on.
var wrapSpeed := 0.0 # Eases up to GROUND_SPEED, so starting from a standstill isn't a jolt. var wrapSpeed := 0.0 # Eases up to GROUND_SPEED, so starting from a standstill isn't a jolt.
var wrapTravelled := 0.0 var wrapTravelled := 0.0
# ---- Lip ----
# Fallback for going over a ceiling edge without the edge hold catching it:
# we hang just past the edge for HOLD_TIME, and pressing up wraps onto the wall above.
const CLIMB_INPUT_BUFFER = 0.15 # Tapping up this long before reaching a lip still counts.
var isHangingOnLip := false
var timeSpentOnLip := 0.0
var lipDirection := 0.0 # Which way we were moving when we went over the lip.
var timeSinceUpPressed := 1.0
# ---- Hops ---- # ---- Hops ----
# Holding up (and not left/right) on the floor for HOLD_TIME hops just high # Holding up (and not left/right) on the floor for HOLD_TIME hops just high
# enough to reach a ceiling up to HOP_REACH above us (measured from our top). # enough to reach a ceiling up to HOP_REACH above us (measured from our top).
@ -116,14 +125,22 @@ func _physics_process(delta: float) -> void:
var horizontalInput := Input.get_axis("moveLeft", "moveRight") var horizontalInput := Input.get_axis("moveLeft", "moveRight")
var verticalInput := Input.get_axis("moveDown", "moveUp") var verticalInput := Input.get_axis("moveDown", "moveUp")
if Input.is_action_just_pressed("moveUp"): timeSinceUpPressed = 0.0
else: timeSinceUpPressed += delta
# Swinging around a corner, ignore everything else until we're done. # Swinging around a corner, ignore everything else until we're done.
if isWrapping: if isWrapping:
_update_wrap(delta) _update_wrap(delta)
return return
var wasInAir := _get_surface_normal() == Vector2.ZERO var wasInAir := _get_surface_normal() == Vector2.ZERO and not isHangingOnLip
if not wasInAir: isHoppingAcross = false if not wasInAir: isHoppingAcross = false
# Hanging on a lip and pressing up: swing around onto the wall above.
var wantsToClimb := verticalInput > 0 or timeSinceUpPressed <= CLIMB_INPUT_BUFFER
if isHangingOnLip and wantsToClimb and _start_lip_wrap():
return
# Near the edge of a surface and pressing into it: wrap over onto the # Near the edge of a surface and pressing into it: wrap over onto the
# side of the platform. # side of the platform.
if isStickingToWall and verticalInput: wallFacingY = -signf(verticalInput) if isStickingToWall and verticalInput: wallFacingY = -signf(verticalInput)
@ -146,7 +163,7 @@ func _physics_process(delta: float) -> void:
if wasOnWall and not isStickingToWall and verticalInput > 0 \ if wasOnWall and not isStickingToWall and verticalInput > 0 \
and timeSpentUnstickingWall < HOLD_TIME and _start_wall_top_wrap(): and timeSpentUnstickingWall < HOLD_TIME and _start_wall_top_wrap():
return return
_update_ceiling_sticking() _update_ceiling_sticking(delta)
# In a corner touching both wall and ceiling, only stick to one # In a corner touching both wall and ceiling, only stick to one
# surface depending on if we're pressing into the ceiling or not. # surface depending on if we're pressing into the ceiling or not.
@ -186,6 +203,10 @@ func _update_vertical_movement(delta: float, horizontalInput: float, verticalInp
# Move up and down along a wall when sticking to it. # Move up and down along a wall when sticking to it.
elif isStickingToWall: elif isStickingToWall:
velocity.y = _accelerate(velocity.y, -CLIMB_SPEED * verticalInput, delta) velocity.y = _accelerate(velocity.y, -CLIMB_SPEED * verticalInput, delta)
# Don't fall while hanging on a lip. Pressing up there normally starts a lip
# wrap first; this only climbs if the wrap couldn't find the corner.
elif isHangingOnLip:
velocity.y = -CLIMB_SPEED if verticalInput > 0 else 0.0
elif not is_on_floor(): elif not is_on_floor():
velocity.y = minf(velocity.y + get_gravity().y * delta, MAX_FALL_SPEED) velocity.y = minf(velocity.y + get_gravity().y * delta, MAX_FALL_SPEED)
@ -218,7 +239,12 @@ func _update_horizontal_movement(delta: float, horizontalInput: float, verticalI
return return
timeSpentUnstickingWall = 0.0 timeSpentUnstickingWall = 0.0
if is_on_floor() or isStickingToCeiling: # Hanging on a lip. Pressing up there normally starts a lip wrap first; if
# that couldn't find the corner, push back towards the platform so physics
# slides us around it onto the wall instead.
if isHangingOnLip:
velocity.x = -lipDirection * WALL_STICK_SPEED if verticalInput > 0 else 0.0
elif is_on_floor() or isStickingToCeiling:
velocity.x = _accelerate(velocity.x, horizontalInput * GROUND_SPEED, delta) velocity.x = _accelerate(velocity.x, horizontalInput * GROUND_SPEED, delta)
elif not isHoppingAcross: elif not isHoppingAcross:
velocity.x = _air_steer(velocity.x, horizontalInput, delta) velocity.x = _air_steer(velocity.x, horizontalInput, delta)
@ -230,11 +256,27 @@ func _update_wall_sticking(wasOnWall: bool) -> void:
and _snap_to_surface(Vector2(wallNormalX, 0))) and _snap_to_surface(Vector2(wallNormalX, 0)))
if isStickingToWall: wallNormalX = get_wall_normal().x if isStickingToWall: wallNormalX = get_wall_normal().x
# After moving: are we still on the ceiling? If we drifted slightly off it, # After moving: are we still on the ceiling, and did we just go over its edge
# pull back onto it instead of falling off. # onto a lip?
func _update_ceiling_sticking() -> void: func _update_ceiling_sticking(delta: float) -> void:
if isHangingOnLip:
timeSpentOnLip += delta
if timeSpentOnLip >= HOLD_TIME: isHangingOnLip = false
else: timeSpentOnLip = 0.0
var wasOnCeiling := isStickingToCeiling var wasOnCeiling := isStickingToCeiling
isStickingToCeiling = is_on_ceiling() or (wasOnCeiling and _snap_to_surface(Vector2.DOWN)) isStickingToCeiling = is_on_ceiling() or (wasOnCeiling and _snap_to_surface(Vector2.DOWN))
# Only walking off the ceiling's edge counts as a lip, not landing on
# a ceiling, letting go of it by pressing down, or after already holding
# at the edge long enough to let go.
if wasOnCeiling and not isStickingToCeiling and not isStickingToWall and velocity.x != 0.0 \
and timeSpentHoldingEdge < HOLD_TIME:
isHangingOnLip = true
lipDirection = signf(velocity.x)
# Made it onto the wall from the lip.
if isHangingOnLip and isStickingToWall:
isHangingOnLip = false
ignoreWallUnstickUntilRelease = true
# Rotates the sprite to sit on the wall or ceiling. Done in _physics_process # Rotates the sprite to sit on the wall or ceiling. Done in _physics_process
# (not _process) so physics interpolation smooths it along with our movement. # (not _process) so physics interpolation smooths it along with our movement.
@ -386,9 +428,23 @@ func _hold_at_edge(delta: float) -> void:
timeSpentHoldingEdge += delta timeSpentHoldingEdge += delta
velocity += direction * (maxf(distanceToEdge, 0.0) / delta - absf(speed)) velocity += direction * (maxf(distanceToEdge, 0.0) / delta - absf(speed))
# Just went over a ceiling edge: find the corner and swing up beside the wall.
func _start_lip_wrap() -> bool:
var direction := lipDirection
var radius := _get_radius()
var pos := global_position
# Bottom of the platform we just came off of.
var ceilingHit := _cast_ray(pos - Vector2(direction * (radius + 2), 0), pos - Vector2(direction * (radius + 2), radius * 2))
if not ceilingHit or ceilingHit.normal.y < 0.5: return false
var ceilingY: float = ceilingHit.position.y
# Side of the platform, just above its bottom.
var faceHit := _cast_ray(Vector2(pos.x + direction * radius, ceilingY - 2), Vector2(pos.x - direction * radius * 2, ceilingY - 2))
if not faceHit or faceHit.normal.x * direction < 0.5: return false
var corner := Vector2(faceHit.position.x, ceilingY)
# After the arc, carry on up the wall so our side is flat against it.
return _begin_wrap(corner, Vector2(direction, 0).angle(), Vector2(0, -radius), Vector2(direction, 0))
# Just climbed past the top of a wall: find the corner and swing up on top. # Just climbed past the top of a wall: find the corner and swing up on top.
# (By now we've already passed the corner, so _find_edge_corner, which looks
# from the surface we're still on, can't see it. Hence the separate raycasts.)
func _start_wall_top_wrap() -> bool: func _start_wall_top_wrap() -> bool:
var wallNormal := wallNormalX var wallNormal := wallNormalX
var radius := _get_radius() var radius := _get_radius()
@ -487,6 +543,7 @@ func _finish_wrap(delta: float) -> void:
velocity = exitDirection * wrapSpeed velocity = exitDirection * wrapSpeed
isWrapping = false isWrapping = false
isHangingOnLip = false
isStickingToCeiling = wrapOntoNormal.y > 0.5 isStickingToCeiling = wrapOntoNormal.y > 0.5
isStickingToWall = absf(wrapOntoNormal.x) > 0.5 isStickingToWall = absf(wrapOntoNormal.x) > 0.5
if isStickingToWall: if isStickingToWall: