Compare commits

..

No commits in common. "c72708e63eb278f7df19711a74b087780fb52a56" and "0db36e2526b7f1432e3516105cecd69e4123ed08" have entirely different histories.

View file

@ -24,10 +24,6 @@ var timeSpentUnstickingCeiling = 0.0
var isClimbingLip = false var isClimbingLip = false
var timeSpentUnstickingLip= 0.0 var timeSpentUnstickingLip= 0.0
var lipDirection := 0.0 # Which way we were moving when we went over the lip.
# After climbing onto a wall from a lip we're usually still holding away from it,
# so don't count that towards unsticking until the direction is released.
var ignoreWallUnstickUntilRelease := false
func _process(delta: float) -> void: func _process(delta: float) -> void:
# Update sprite to be on the wall or ceiling. In a corner only one of them # Update sprite to be on the wall or ceiling. In a corner only one of them
@ -61,9 +57,9 @@ func _physics_process(delta: float) -> void:
# 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 = CLIMB_SPEED * verticalInput velocity.y = CLIMB_SPEED * verticalInput
# Don't fall if climbing lip. Pressing up climbs onto the wall above. # Don't fall if climbing lip.
elif isClimbingLip: elif isClimbingLip:
velocity.y = CLIMB_SPEED if verticalInput > 0 else 0.0 velocity.y = 0
# Else... just fall. # Else... just fall.
elif not is_on_floor(): elif not is_on_floor():
velocity.y += get_gravity().y * delta velocity.y += get_gravity().y * delta
@ -72,8 +68,7 @@ func _physics_process(delta: float) -> void:
# If sticking to a wall, pressing away from it long enough gets us unstuck. # If sticking to a wall, pressing away from it long enough gets us unstuck.
if isStickingToWall and not is_on_floor(): if isStickingToWall and not is_on_floor():
var pressingAwayFromWall := horizontalInput * wallNormalX > 0 var pressingAwayFromWall := horizontalInput * wallNormalX > 0
if not pressingAwayFromWall: ignoreWallUnstickUntilRelease = false if pressingAwayFromWall: timeSpentUnstickingWall += delta
if pressingAwayFromWall and not ignoreWallUnstickUntilRelease: timeSpentUnstickingWall += delta
else: timeSpentUnstickingWall = 0.0 else: timeSpentUnstickingWall = 0.0
if timeSpentUnstickingWall >= MAX_SECS_TO_UNSTICK: if timeSpentUnstickingWall >= MAX_SECS_TO_UNSTICK:
velocity.x = horizontalInput * GROUND_SPEED velocity.x = horizontalInput * GROUND_SPEED
@ -82,10 +77,9 @@ func _physics_process(delta: float) -> void:
# Otherwise move horizontally based on what we're on. # Otherwise move horizontally based on what we're on.
else: else:
timeSpentUnstickingWall = 0.0 timeSpentUnstickingWall = 0.0
# Hang on the lip. Pressing up pushes back towards the platform so we
# slide around the corner and touch the wall.
if isClimbingLip: if isClimbingLip:
velocity.x = -lipDirection * WALL_STICK_SPEED if verticalInput > 0 else 0.0 velocity.x = move_toward(velocity.x, 0, GROUND_SPEED)
print(velocity.x)
elif horizontalInput and (is_on_floor() or isStickingToCeiling): elif horizontalInput and (is_on_floor() or isStickingToCeiling):
velocity.x = horizontalInput * GROUND_SPEED velocity.x = horizontalInput * GROUND_SPEED
elif horizontalInput and not (is_on_floor() or isStickingToCeiling): elif horizontalInput and not (is_on_floor() or isStickingToCeiling):
@ -109,15 +103,8 @@ func _physics_process(delta: float) -> void:
else: timeSpentUnstickingLip = 0.0 else: timeSpentUnstickingLip = 0.0
var wasJustOnCeiling = isStickingToCeiling var wasJustOnCeiling = isStickingToCeiling
isStickingToCeiling = is_on_ceiling() isStickingToCeiling = is_on_ceiling()
# Only walking off the ceiling's edge counts as a lip, not landing on if (wasJustOnCeiling != isStickingToCeiling) and not isStickingToWall:
# a ceiling or letting go of it by pressing down.
if wasJustOnCeiling and not isStickingToCeiling and not isStickingToWall and velocity.x:
isClimbingLip = true isClimbingLip = true
lipDirection = signf(velocity.x)
# Made it onto the wall from the lip.
if isClimbingLip and isStickingToWall:
isClimbingLip = false
ignoreWallUnstickUntilRelease = true
# 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.