From 09794cc76678247592ceb4e8b37e1ab129356466 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 24 Dec 2023 16:16:25 +0100 Subject: better wall jumps --- Characters/Character.gd | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'Characters/Character.gd') diff --git a/Characters/Character.gd b/Characters/Character.gd index 53260f2..b9bcd16 100644 --- a/Characters/Character.gd +++ b/Characters/Character.gd @@ -6,13 +6,19 @@ const JUMPFORCE = -500 const GRAVITY = 20 const RUNSPEED = SPEED * 2 const WALLJUMPFORCE = JUMPFORCE * 0.75 -const WALLJUMPSPEED = SPEED * 10 +const WALLJUMPSPEED = SPEED * 8 var direction = Enum.DIRECTION.RIGHT var canDoubleJump = false var hasPlayedFallStop = false var jumpHeightModifier = 0 +var wasOnWall = false +var lastWallDirection = Enum.DIRECTION.LEFT + + +func _ready(): + pass func _physics_process(delta): @@ -69,7 +75,7 @@ func _physics_process(delta): canDoubleJump = true velocity.y = JUMPFORCE jumpHeightModifier = JUMPFORCE - elif not is_on_floor() and not is_on_wall() and canDoubleJump: + elif not is_on_floor() and not is_on_wall() and not wasOnWall and canDoubleJump: canDoubleJump = false velocity.y = JUMPFORCE if Input.is_action_pressed("JUMP"): @@ -80,18 +86,25 @@ func _physics_process(delta): velocity.y -= jumpHeightModifier - if is_on_wall(): + if is_on_wall() and not is_on_floor(): velocity.y *= 0.8 $Sprite2D.play("wall") - - if Input.is_action_just_pressed("JUMP"): - velocity.y = WALLJUMPFORCE - if direction == Enum.DIRECTION.LEFT: - velocity.x = WALLJUMPSPEED - $Sprite2D.flip_h = false - elif direction == Enum.DIRECTION.RIGHT: - velocity.x = -WALLJUMPSPEED - $Sprite2D.flip_h = true + wasOnWall = true + lastWallDirection = direction + + if not is_on_wall() and wasOnWall: + wasOnWall = false + $WalljumpTimer.start() + + if canWallJump() and Input.is_action_just_pressed("JUMP"): + $WalljumpTimer.stop() + velocity.y = WALLJUMPFORCE + if lastWallDirection == Enum.DIRECTION.LEFT: + velocity.x = WALLJUMPSPEED + $Sprite2D.flip_h = false + elif lastWallDirection == Enum.DIRECTION.RIGHT: + velocity.x = -WALLJUMPSPEED + $Sprite2D.flip_h = true # stop @@ -105,7 +118,7 @@ func is_running(): func canWallJump(): - return self.wallJumpGraceTimer < 0.1 + return (is_on_wall() and not is_on_floor()) or not $WalljumpTimer.is_stopped() func check_flag(): -- cgit v1.2.3