diff --git a/Characters/player.gd b/Characters/player.gd index 5fe095e..b104792 100755 --- a/Characters/player.gd +++ b/Characters/player.gd @@ -22,6 +22,9 @@ var wallNormalX := 0.0 var isStickingToCeiling := false var timeSpentUnstickingCeiling = 0.0 +var isClimbingLip = false +var timeSpentUnstickingLip= 0.0 + func _process(delta: float) -> void: # Update sprite to be on the wall or ceiling. In a corner only one of them # is ever true (that gets decided at the end of _physics_process). @@ -51,10 +54,13 @@ func _physics_process(delta: float) -> void: isStickingToCeiling = false velocity.y = get_gravity().y * delta else: velocity.y = CEILING_STICK_SPEED - # Move up and down along a wall when sticking to it. elif isStickingToWall: velocity.y = CLIMB_SPEED * verticalInput + # Don't fall if climbing lip. + elif isClimbingLip: + velocity.y = 0 + # Else... just fall. elif not is_on_floor(): velocity.y += get_gravity().y * delta @@ -71,7 +77,10 @@ func _physics_process(delta: float) -> void: # Otherwise move horizontally based on what we're on. else: timeSpentUnstickingWall = 0.0 - if horizontalInput and (is_on_floor() or isStickingToCeiling): + if isClimbingLip: + velocity.x = move_toward(velocity.x, 0, GROUND_SPEED) + print(velocity.x) + elif horizontalInput and (is_on_floor() or isStickingToCeiling): velocity.x = horizontalInput * GROUND_SPEED elif horizontalInput and not (is_on_floor() or isStickingToCeiling): velocity.x = horizontalInput * AIR_SPEED @@ -85,8 +94,17 @@ func _physics_process(delta: float) -> void: if isStickingToWall: wallNormalX = get_wall_normal().x - # Check if we are attempting to climb a lip. + # Set if we're sticking to a ceiling. + # Also check if we started climbing a lip. + if isClimbingLip: + timeSpentUnstickingLip += delta + if timeSpentUnstickingLip >= MAX_SECS_TO_UNSTICK: + isClimbingLip = false + else: timeSpentUnstickingLip = 0.0 + var wasJustOnCeiling = isStickingToCeiling isStickingToCeiling = is_on_ceiling() + if (wasJustOnCeiling != isStickingToCeiling) and not isStickingToWall: + isClimbingLip = true # In a corner touching both wall and ceiling, only stick to one # surface depending on if we're pressing into the ceiling or not.