Added lip climbing
This commit is contained in:
parent
64188a72d3
commit
0db36e2526
1 changed files with 21 additions and 3 deletions
|
|
@ -22,6 +22,9 @@ var wallNormalX := 0.0
|
||||||
var isStickingToCeiling := false
|
var isStickingToCeiling := false
|
||||||
var timeSpentUnstickingCeiling = 0.0
|
var timeSpentUnstickingCeiling = 0.0
|
||||||
|
|
||||||
|
var isClimbingLip = false
|
||||||
|
var timeSpentUnstickingLip= 0.0
|
||||||
|
|
||||||
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
|
||||||
# is ever true (that gets decided at the end of _physics_process).
|
# is ever true (that gets decided at the end of _physics_process).
|
||||||
|
|
@ -51,10 +54,13 @@ func _physics_process(delta: float) -> void:
|
||||||
isStickingToCeiling = false
|
isStickingToCeiling = false
|
||||||
velocity.y = get_gravity().y * delta
|
velocity.y = get_gravity().y * delta
|
||||||
else: velocity.y = CEILING_STICK_SPEED
|
else: velocity.y = CEILING_STICK_SPEED
|
||||||
|
|
||||||
# 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.
|
||||||
|
elif isClimbingLip:
|
||||||
|
velocity.y = 0
|
||||||
|
# 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
|
||||||
|
|
||||||
|
|
@ -71,7 +77,10 @@ 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
|
||||||
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
|
velocity.x = horizontalInput * GROUND_SPEED
|
||||||
elif horizontalInput and not (is_on_floor() or isStickingToCeiling):
|
elif horizontalInput and not (is_on_floor() or isStickingToCeiling):
|
||||||
velocity.x = horizontalInput * AIR_SPEED
|
velocity.x = horizontalInput * AIR_SPEED
|
||||||
|
|
@ -85,8 +94,17 @@ func _physics_process(delta: float) -> void:
|
||||||
if isStickingToWall:
|
if isStickingToWall:
|
||||||
wallNormalX = get_wall_normal().x
|
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()
|
isStickingToCeiling = is_on_ceiling()
|
||||||
|
if (wasJustOnCeiling != isStickingToCeiling) and not isStickingToWall:
|
||||||
|
isClimbingLip = 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.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue