summaryrefslogtreecommitdiff
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
parent395c25b1fbe51f42decf402f97e51eabcc8c0a77 (diff)
better wall jumps
-rw-r--r--Characters/Character.gd39
-rw-r--r--Characters/Character.tscn4
-rw-r--r--Characters/Tux.gd4
-rw-r--r--Characters/Tux.tscn4
-rw-r--r--Global.gd1
-rw-r--r--Readme.md2
-rw-r--r--project.godot2
7 files changed, 38 insertions, 18 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
diff --git a/Global.gd b/Global.gd
index d326cc6..9cb1001 100644
--- a/Global.gd
+++ b/Global.gd
@@ -15,6 +15,7 @@ var Levels = [
"Level_0005",
"Level_0005",
"Level_0004",
+ "Level_0003",
"Level_0002",
"Level_0001",
]
diff --git a/Readme.md b/Readme.md
new file mode 100644
index 0000000..6747efa
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1,2 @@
+- [How to Make Wall Jump & Slide in Godot [Easy in 3 Minutes]](https://youtu.be/vNHIMrTWpt8)
+- [How to Create WALL JUMPING & SLIDING in Godot 4](https://youtu.be/5FWzWrK6jLM)
diff --git a/project.godot b/project.godot
index ae2e1f3..f41802a 100644
--- a/project.godot
+++ b/project.godot
@@ -12,7 +12,7 @@ config_version=5
config/name="TicTacTux"
run/main_scene="res://Network/Lobby.tscn"
-config/features=PackedStringArray("4.0")
+config/features=PackedStringArray("4.2")
config/icon="res://icon.png"
[autoload]