Hey, i want to make a game where you have blocks wich can be broken an build so the player has to move over them smothly. I was asking about this issue yesterday, when i was told that the Box2d engine isnt the best for this task. So i then dove into AABB collision and got it working. So now, i have a collide() function wich takes x1, y1, width1, height1 and x2, y2, width2, height2 and returns a bool. I then made a for loop that goes thru the blocks in my Map and calls the collide functoin on them and the player. I did something like this pseudo code, to determine what side / where the collison took place:
Code: Select all
for blocks do
if collision(player, box) then
if player.y > box.y then
hit ceiling
elseif player.y < box.y then
hit ground
elseif player.x > box.x then
stop moving on x axsis
elseif player.x < box.x then
stop moving on x axsis
end
end
end
I then noticed it wouldnt let me move side to side because it check for all of the blocks, wich ended with the player not being able to move horizontally, wich makes sense.
I then thought i should only check for the two nearest blocks, so it wouldnt happen and even tho im not sure if it would work started trying.
then for what ever reason, it told me that the function arguments in this function were nil or tabel values, wich doesnt make sense, so now i am completly stuck.
Code: Select all
function distance ( x1, y1, x2, y2 )
local dx = x1 - x2
local dy = y1 - y2
return math.sqrt ( dx * dx + dy * dy )
end
I am completly stuck and just want to move from physics
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle