summaryrefslogtreecommitdiff
path: root/Characters/Character.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2023-12-24 16:16:25 +0100
committerDaniel Weipert <git@mail.dweipert.de>2023-12-24 16:16:25 +0100
commit09794cc76678247592ceb4e8b37e1ab129356466 (patch)
tree7779463728a2df808b4cf049160468c5324ee787 /Characters/Character.gd
parent395c25b1fbe51f42decf402f97e51eabcc8c0a77 (diff)
better wall jumps
Diffstat (limited to 'Characters/Character.gd')
-rw-r--r--Characters/Character.gd39
1 files changed, 26 insertions, 13 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():