Posted 28 May 2016 - 07:16 PM
I'm currently in the process of making a platform game, and I have a problem which I don't know how to fix.
For some reason, the collision detection with the tilemap only works in a straight line. Anything not in a straight line just doesn't register, which seems fairly weird to me, because I'm using the same table for rendering as I am for collision.
Basically, the map is divided into multiple tables: The object table, the block table and the tile table.
The object and block table are tables, which have a similar structure: {x, y, char, tColor, bColor} with some additional info for each.
The tile table is a 2D table, consisting only of characters, whose drawing is hardcoded into the renderer. (For example, if the character it finds is a "#", it draws a quote, with a green background color and a lime text color, putting some "grass" on the screen.)
The collision for the player and the tile is handled using one function:
If there's any more information needed, just tell me. I'll gladly clarify :)/>
Oh, and thanks for any help I get :)/>
For some reason, the collision detection with the tilemap only works in a straight line. Anything not in a straight line just doesn't register, which seems fairly weird to me, because I'm using the same table for rendering as I am for collision.
Basically, the map is divided into multiple tables: The object table, the block table and the tile table.
The object and block table are tables, which have a similar structure: {x, y, char, tColor, bColor} with some additional info for each.
The tile table is a 2D table, consisting only of characters, whose drawing is hardcoded into the renderer. (For example, if the character it finds is a "#", it draws a quote, with a green background color and a lime text color, putting some "grass" on the screen.)
The collision for the player and the tile is handled using one function:
local function CheckForTile(x, y)
do -- If the map is nothing, return nil
if playerCurrentState == playerStates.PLAYER_SMALL then
for i = 1, #currentMap do
for w = 1, #currentMap[i] do
if w == x and i == y then
if currentMap[i][w] ~= " " then return currentMap[i][w] else return nil end
end
end
end
else
for i = 1, #currentMap do
for w = 1, #currentMap[i] do
if (w == x and y+1 >= i and y <= i) then
if currentMap[i][w] ~= " " then return currentMap[i][w] else return nil end
end
end
end
end
end
end
This error popped up only recently, and never before. I suspect it has something to do with the fact that I added loading maps to my map editor, since the error started happening pretty much at the same time.If there's any more information needed, just tell me. I'll gladly clarify :)/>
Oh, and thanks for any help I get :)/>