I solved the first and the third question, but i don't know how to solve the second problem.
This code works with the square tiles, but doesn't if the player is on a slope.
Code: Select all
function createPlayer(x, y)
if #players < 5 then
local nPlayer = #players+1
players[nPlayer] = {}
local body = love.physics.newBody( level, x, y, 'dynamic' )
local pShape = love.physics.newPolygonShape( 0.25, 0.4, 0.75, 0.4, 1, 0.65, 1, 1.75, 0.75, 2, 0.25, 2, 0, 1.75, 0, 0.65 )
--body:setGravityScale(0)
body:setFixedRotation(true)
local fixture = love.physics.newFixture( body, pShape, 1 )
fixture:setFriction(0)
fixture:setRestitution(0)
local sShape = love.physics.newRectangleShape( 0.26, 1.9, 0.48, 0.5, 0 )
local sensor = love.physics.newFixture( body, sShape, 1 )
sensor:setSensor( true )
sensor:setFriction(0)
sensor:setRestitution(0)
body:setMassData( 0.5, 1, 80, 0 )
players[nPlayer] = { body, pShape, fixture, sensor, false, false, 0, false, 0 }
end
end
What is the best way to know if a body is colliding with a slope?
function beginContact(a, b)
if a == players[1][4] or b == players[1][4] then
players[1][9] = players[1][9] + 1
players[1][8] = true
end
end
function endContact(a, b)
if a == players[1][4] or b == players[1][4] then
players[1][9] = players[1][9] - 1
if players[1][9] <= 0 then
players[1][8] = false
end
end
end