Condense collision detection into 1 function
This commit is contained in:
parent
8299487d6f
commit
8ca5c029f8
@ -3,17 +3,17 @@
|
||||
|
||||
--squared collision detection
|
||||
player.on_block = false
|
||||
function collisiony(oldposy)
|
||||
--stairs
|
||||
--if (player.playerx <= map_max and player.playerx > 1) and
|
||||
-- (player.playery < map_max and player.playery > 1) and
|
||||
-- loaded_chunks[0][0][player.playerx][player.playery]["block"] == 3 then
|
||||
-- player.playery = player.playery - 1
|
||||
function collision(oldposx,oldposy)
|
||||
--do stairs
|
||||
|
||||
|
||||
|
||||
local xer = {0.3,0.7}
|
||||
local yer = {0,1}
|
||||
local fall = true
|
||||
|
||||
--check the corners
|
||||
--check the corners (y)
|
||||
player.playery = player.playery + player.inertiay
|
||||
for q = 1,2 do
|
||||
for r = 1,2 do
|
||||
local squarex1 = math.floor(player.playerx+xer[q])
|
||||
@ -34,18 +34,10 @@ function collisiony(oldposy)
|
||||
if fall == true then
|
||||
player.on_block = false
|
||||
end
|
||||
end
|
||||
function collisionx(oldposx)
|
||||
--stairs
|
||||
--if (player.playerx <= map_max and player.playerx > 1) and
|
||||
-- (player.playery < map_max and player.playery > 1) and
|
||||
-- loaded_chunks[0][0][player.playerx][player.playery]["block"] == 3 then
|
||||
-- player.playery = player.playery - 1
|
||||
local xer = {0.3,0.7}
|
||||
local yer = {0,1}
|
||||
local fall = true
|
||||
|
||||
--check the corners
|
||||
|
||||
--check the corners(x)
|
||||
player.playerx = player.playerx + player.inertiax
|
||||
for q = 1,2 do
|
||||
for r = 1,2 do
|
||||
local squarex1 = math.floor(player.playerx+xer[q])
|
||||
@ -59,6 +51,17 @@ function collisionx(oldposx)
|
||||
end
|
||||
end
|
||||
end
|
||||
function collisionx(oldposx)
|
||||
--do stairs
|
||||
|
||||
|
||||
|
||||
local xer = {0.3,0.7}
|
||||
local yer = {0,1}
|
||||
local fall = true
|
||||
|
||||
|
||||
end
|
||||
|
||||
--make the player fall when in air
|
||||
gravtimer = 0
|
||||
|
@ -24,12 +24,10 @@ function physics.player_mod_y(value)
|
||||
end
|
||||
--apply left and right
|
||||
function physics.player_x_apply(dt)
|
||||
local oldposx,oldposy = player.playerx,player.playery
|
||||
--local oldposx,oldposy = player.playerx,player.playery
|
||||
|
||||
player.playery = player.playery + player.inertiay
|
||||
collisiony(oldposy)
|
||||
player.playerx = player.playerx + player.inertiax
|
||||
collisionx(oldposx)
|
||||
collision(player.playerx,player.playery)
|
||||
--collisionx(oldposx)
|
||||
--print(player.inertiax)
|
||||
if math.abs(player.inertiax) <= 0.005 then
|
||||
player.inertiax = 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user