Skip to content

Commit

Permalink
Tweaked platform ground and wall contact variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Björn Ritzl committed Feb 14, 2017
1 parent edf2146 commit 83362c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions examples/platformer/player.script
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local JUMP = hash("jump")
function init(self)
input.acquire()
self.physics = platformer.create({ hash("ground") })
self.physics.gravity = -800
self.physics.gravity = -1200
end

function final(self)
Expand All @@ -17,9 +17,9 @@ end

function update(self, dt)
if input.is_pressed(LEFT) then
self.physics.left(140)
self.physics.left(240)
elseif input.is_pressed(RIGHT) then
self.physics.right(140)
self.physics.right(240)
else
self.physics.stop()
end
Expand All @@ -36,7 +36,7 @@ function on_input(self, action_id, action)
if action_id == JUMP then
if action.pressed then
print("jmp")
self.physics.jump(800)
self.physics.jump(1000)
elseif action.released then
self.physics.abort_jump()
end
Expand Down
14 changes: 8 additions & 6 deletions ludobits/m/platformer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ function M.create(collision_hashes)
ground_contact = false,
wall_contact = false,
jumping = false,
double_jumping = false,
}

local correction = vmath.vector3()
local double_jumping = false

local function jumping_up()
return (instance.velocity.y > 0 and instance.gravity < 0) or (instance.velocity.y < 0 and instance.gravity > 0)
Expand Down Expand Up @@ -48,9 +48,10 @@ function M.create(collision_hashes)
instance.velocity.y = power * 0.75
instance.velocity.x = instance.wall_contact.x * power * 0.35
instance.jumping = true
elseif allow_double_jump and jumping_up() and not double_jumping then
instance.wall_jumping = true
elseif allow_double_jump and jumping_up() and not instance.double_jumping then
instance.velocity.y = instance.velocity.y + power
double_jumping = true
instance.double_jumping = true
end
end

Expand Down Expand Up @@ -79,11 +80,12 @@ function M.create(collision_hashes)
if proj < 0 then
instance.velocity = instance.velocity - proj * message.normal
end
instance.wall_contact = message.normal.x ~= 0 and message.normal or instance.wall_contact
instance.ground_contact = instance.ground_contact or message.normal.y ~= 0
instance.wall_contact = math.abs(message.normal.x) > 0.8 and message.normal or instance.wall_contact
instance.ground_contact = message.normal.y ~= 0 and message.normal or instance.ground_contact
if message.normal.y ~= 0 then
instance.jumping = false
double_jumping = false
instance.double_jumping = false
instance.wall_jumping = false
end
end
end
Expand Down

0 comments on commit 83362c9

Please sign in to comment.