diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2023-12-24 16:16:25 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2023-12-24 16:16:25 +0100 |
commit | 09794cc76678247592ceb4e8b37e1ab129356466 (patch) | |
tree | 7779463728a2df808b4cf049160468c5324ee787 /Characters | |
parent | 395c25b1fbe51f42decf402f97e51eabcc8c0a77 (diff) |
better wall jumps
Diffstat (limited to 'Characters')
-rw-r--r-- | Characters/Character.gd | 39 | ||||
-rw-r--r-- | Characters/Character.tscn | 4 | ||||
-rw-r--r-- | Characters/Tux.gd | 4 | ||||
-rw-r--r-- | Characters/Tux.tscn | 4 |
4 files changed, 34 insertions, 17 deletions
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(): diff --git a/Characters/Character.tscn b/Characters/Character.tscn index 3016f35..055d754 100644 --- a/Characters/Character.tscn +++ b/Characters/Character.tscn @@ -110,3 +110,7 @@ shape = SubResource("2") target_position = Vector2(0, 150) [node name="CheckFallLanding" type="RayCast2D" parent="."] + +[node name="WalljumpTimer" type="Timer" parent="."] +wait_time = 0.1 +one_shot = true diff --git a/Characters/Tux.gd b/Characters/Tux.gd index b7c6d31..048d59c 100644 --- a/Characters/Tux.gd +++ b/Characters/Tux.gd @@ -1,5 +1 @@ extends "res://Characters/Character.gd" - - -func _ready(): - pass diff --git a/Characters/Tux.tscn b/Characters/Tux.tscn index fdda659..6a5b6de 100644 --- a/Characters/Tux.tscn +++ b/Characters/Tux.tscn @@ -111,3 +111,7 @@ shape = SubResource("2") target_position = Vector2(0, 150) [node name="CheckFallLanding" type="RayCast2D" parent="."] + +[node name="WalljumpTimer" type="Timer" parent="."] +wait_time = 0.25 +one_shot = true |