Hi,
I have been trying to make a platformer game using LÖVE Physics, almost everything works fine, but i have three questions about slopes:
1º How can I prevent the player from falling off over the slopes?
2º What can I do to detect if the player is over a slope?
3º How can I prevent the player jumping at the top of a slope?
* My english it's really bad, so i attached an image showing the related issue.
Slope issues
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- AlexsSteel
- Prole
- Posts: 17
- Joined: Sat Dec 27, 2014 2:11 am
Slope issues
- Attachments
-
- platf.love
- (2.26 KiB) Downloaded 314 times
Re: Slope issues
How about checking this thread? markgo made good example before, I hope it can help you.
viewtopic.php?f=5&t=12214
viewtopic.php?f=5&t=12214
- AlexsSteel
- Prole
- Posts: 17
- Joined: Sat Dec 27, 2014 2:11 am
Re: Slope issues
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.
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
- AlexsSteel
- Prole
- Posts: 17
- Joined: Sat Dec 27, 2014 2:11 am
Re: Slope issues
Don't worry, i solved it.
Re: Slope issues
I found this article on slopes quite helpful:
http://concernedjoe.com/devblog/hardcoding-slopes/
Concerned Joe <3
http://concernedjoe.com/devblog/hardcoding-slopes/
Concerned Joe <3
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Slope issues
That's not really solving your slope issue. It's creating a workaround to avoid solving the problem.AlexsSteel wrote:Don't worry, i solved it.
Re: Slope issues
I'd say thats a pretty legit way of doing slopes with box2DJasoco wrote:That's not really solving your slope issue. It's creating a workaround to avoid solving the problem.AlexsSteel wrote:Don't worry, i solved it.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests