Skip to content

Commit

Permalink
Merge pull request #41 from vegeta897/patch-1
Browse files Browse the repository at this point in the history
Add slipping past walls when jumping, #35
  • Loading branch information
TaylorAnderson authored Apr 9, 2022
2 parents fc7db74 + e603f48 commit 5d4b48c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion scripts/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const JUMPFORCE = 1100
const ACCEL = 50
const COYOTE_TIME = 0.1
const JUMP_BUFFER_TIME = 0.05
const JUMP_SLIP_RANGE = 16

var coyote_timer = COYOTE_TIME # used to give a bit of extra-time to jump after leaving the ground
var jump_buffer_timer = 0 # gives a bit of buffer to hit the jump button before landing
Expand Down Expand Up @@ -79,7 +80,28 @@ func _physics_process(delta : float) -> void:
crouching = false
unsquash()

motion = move_and_slide(motion, UP)
var move_and_slide_result = move_and_slide(motion, UP)
var slide_count = get_slide_count()
# check for an upwards-collision
if slide_count && get_slide_collision(slide_count-1).get_angle(Vector2(0,1)) == 0:
var slipped = try_jump_slip() # try to adjust player position to "slip" past a wall
if !slipped:
motion = move_and_slide_result # apply original result if no valid slip found
else:
motion = move_and_slide_result

func try_jump_slip():
var original_x = position.x # remember original x position
# check collisions in nearby x positions within JUMP_SLIP_RANGE
for x in range(1, JUMP_SLIP_RANGE):
for p in [-1, 1]:
position.x = original_x + x * p
move_and_slide(motion, UP)
if(get_slide_count() == 0):
return true # if no collision, return success
# restore original x position if couldn't find a slip
position.x = original_x
return false

func crouch():
crouching = true
Expand Down

0 comments on commit 5d4b48c

Please sign in to comment.