Skip to content

Commit 83362c9

Browse files
author
Björn Ritzl
committed
Tweaked platform ground and wall contact variables
1 parent edf2146 commit 83362c9

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

examples/platformer/player.script

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local JUMP = hash("jump")
88
function init(self)
99
input.acquire()
1010
self.physics = platformer.create({ hash("ground") })
11-
self.physics.gravity = -800
11+
self.physics.gravity = -1200
1212
end
1313

1414
function final(self)
@@ -17,9 +17,9 @@ end
1717

1818
function update(self, dt)
1919
if input.is_pressed(LEFT) then
20-
self.physics.left(140)
20+
self.physics.left(240)
2121
elseif input.is_pressed(RIGHT) then
22-
self.physics.right(140)
22+
self.physics.right(240)
2323
else
2424
self.physics.stop()
2525
end
@@ -36,7 +36,7 @@ function on_input(self, action_id, action)
3636
if action_id == JUMP then
3737
if action.pressed then
3838
print("jmp")
39-
self.physics.jump(800)
39+
self.physics.jump(1000)
4040
elseif action.released then
4141
self.physics.abort_jump()
4242
end

ludobits/m/platformer.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ function M.create(collision_hashes)
1515
ground_contact = false,
1616
wall_contact = false,
1717
jumping = false,
18+
double_jumping = false,
1819
}
1920

2021
local correction = vmath.vector3()
21-
local double_jumping = false
2222

2323
local function jumping_up()
2424
return (instance.velocity.y > 0 and instance.gravity < 0) or (instance.velocity.y < 0 and instance.gravity > 0)
@@ -48,9 +48,10 @@ function M.create(collision_hashes)
4848
instance.velocity.y = power * 0.75
4949
instance.velocity.x = instance.wall_contact.x * power * 0.35
5050
instance.jumping = true
51-
elseif allow_double_jump and jumping_up() and not double_jumping then
51+
instance.wall_jumping = true
52+
elseif allow_double_jump and jumping_up() and not instance.double_jumping then
5253
instance.velocity.y = instance.velocity.y + power
53-
double_jumping = true
54+
instance.double_jumping = true
5455
end
5556
end
5657

@@ -79,11 +80,12 @@ function M.create(collision_hashes)
7980
if proj < 0 then
8081
instance.velocity = instance.velocity - proj * message.normal
8182
end
82-
instance.wall_contact = message.normal.x ~= 0 and message.normal or instance.wall_contact
83-
instance.ground_contact = instance.ground_contact or message.normal.y ~= 0
83+
instance.wall_contact = math.abs(message.normal.x) > 0.8 and message.normal or instance.wall_contact
84+
instance.ground_contact = message.normal.y ~= 0 and message.normal or instance.ground_contact
8485
if message.normal.y ~= 0 then
8586
instance.jumping = false
86-
double_jumping = false
87+
instance.double_jumping = false
88+
instance.wall_jumping = false
8789
end
8890
end
8991
end

0 commit comments

Comments
 (0)