Doh! Another silly mistake on my part - thanks very much for pointing that out to me.
EDIT: I have a more 'Collision' based issue that I will just add to this thread.
I have set up my world - it all runs ok with no errors. I use a 'body:setX(body:getX + 5)' on keyDown.love.key_right etc to move my bodies/shapes. However collisions just will not detect. I am missing something? I tried adding mass and gravity but to no prevail. Just a quick note - I've left some Variables out of the code posted here so you can see just what I have effecting the world - rest assured that any variable you see has been initiliased.
Code: Select all
text = "No collision yet."
function load()
world = love.physics.newWorld(800, 500)
player = love.physics.newBody(world, 388, 400, 5)
player_box = love.physics.newRectangleShape(player, 100, 100)
player_box:setData("Player")
arwing_eng_emit_x = player:getX()
arwing_eng_emit_y = player:getY() + 30
vexxer_one = love.physics.newBody(world, vexxer_one_x, vexxer_one_y, 5)
vexxer_one_box = love.physics.newRectangleShape(vexxer_one, 100, 100)
vexxer_one_box:setData("Vexxer_one")
world:setCallback(collision)
end
function draw()
--- Just moves my 'Engine Wash' emitter with the ship
arwing_eng_emit_x = player:getX()
arwing_eng_emit_y = player:getY() + 30
--- handles the ships movement
if love.keyboard.isDown(love.key_left) and canmoveleft == 1 and level_one == 1 then
player:setX(player:getX() - 5)
arwing_eng_emit_x = arwing_eng_emit_x -5
elseif love.keyboard.isDown(love.key_right) and canmoveright == 1 and level_one == 1 then
player:setX(player:getX() + 5)
arwing_eng_emit_x = arwing_eng_emit_x + 5
end
end
function update(dt)
world:update(dt)
end
function collision(a, b, c)
local f, r = c:getFriction(), c:getRestitution()
local s = c:getSeparation()
local px, py = c:getPosition()
local vx, vy = c:getVelocity()
local nx, ny = c:getNormal()
text = "Last Collision:\n"
text = text .. "Shapes: " .. a .. " and " .. b .. "\n"
text = text .. "Position: " .. px .. "," .. py .. "\n"
text = text .. "Velocity: " .. vx .. "," .. vy .. "\n"
text = text .. "Normal: " .. nx .. "," .. ny .. "\n"
text = text .. "Friction: " .. f .. "\n"
text = text .. "Restitution: " .. r .. "\n"
text = text .. "Separation: " .. s .. "\n"
end
Ideally I just want to check postions - if the hitboxes overlap etc, I don't really want them to block movement or check speeds. No Collision is detected - none that I can tell. Part of me is concerned I've haven't set the hitboxes up, as I'm aware there should be 4 variables for a shape? the x,y of where it is draw, and then the size of the box in x,y - I did try
Code: Select all
player_box = love.physics.newRectangleShape(player, player:getX(), player:getY(), 100, 100)
But then everything just stopped moving.