간단한 플랫폼 게임을 만들기 위해 노력 중이며 분명히 타일 충돌이 필요합니다. 내가 지금까지 가지고있는 코드의 문제점은 캐릭터를 먼저 움직이고 충돌이 있는지를 확인하는 것이지만 때로는 충돌을 위해 x 축을 먼저 검사하는지에 따라 잘못된 시간에 충돌을 생각하는 경우가 있습니다 또는 y 축을 먼저 찾습니다. 내가 잘못된 방향으로가는거야? 여기에 몇 가지 코드가 있습니다.타일 기반 충돌을 수행하는 방법
function checkCollision(val, axis, oldPos)
if axis == "x" and char.tX then
local tileX = math.ceil(val/absoluteTileSize)
local tileY = math.floor(oldPos/absoluteTileSize)
local tl, tr, bl ,br = getTouchingTiles(tileX, tileY)
local isOnFlatSurface = math.abs(oldPos/absoluteTileSize-tileY) <= .00001--might not be a good i
if isOnFlatSurface then
if tr.canCollide then
char.tX = nil
char.x = tileX * absoluteTileSize - absoluteTileSize
end
else
if br.canCollide then
char.tX = nil
char.x = tileX * absoluteTileSize - absoluteTileSize
end
end
elseif axis == "y" then
local tileX = math.ceil(oldPos/absoluteTileSize)
local tileY = math.floor(val/absoluteTileSize)
local tl, tr, bl ,br = getTouchingTiles(tileX, tileY)
if bl.canCollide or br.canCollide then
char.tY = nil
char.y = tileY * absoluteTileSize --// - absoluteTileSize
--/////////////idk why i don't need to subtract that but it works
elseif not char.tY then--start falling if walk off something
char.tY = love.timer.getTime()
char.yi = char.y
char.vyi = 0
end
end
end