Slope issues

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
AlexsSteel
Prole
Posts: 17
Joined: Sat Dec 27, 2014 2:11 am

Slope issues

Post by AlexsSteel »

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.

Image
Attachments
platf.love
(2.26 KiB) Downloaded 314 times
User avatar
norubal
Party member
Posts: 137
Joined: Tue Jan 15, 2013 5:55 am

Re: Slope issues

Post by norubal »

How about checking this thread? markgo made good example before, I hope it can help you.
viewtopic.php?f=5&t=12214
User avatar
AlexsSteel
Prole
Posts: 17
Joined: Sat Dec 27, 2014 2:11 am

Re: Slope issues

Post by AlexsSteel »

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
User avatar
AlexsSteel
Prole
Posts: 17
Joined: Sat Dec 27, 2014 2:11 am

Re: Slope issues

Post by AlexsSteel »

Don't worry, i solved it.

Image
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Slope issues

Post by rmcode »

I found this article on slopes quite helpful:

http://concernedjoe.com/devblog/hardcoding-slopes/

Concerned Joe <3
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Slope issues

Post by Jasoco »

AlexsSteel wrote:Don't worry, i solved it.

Image
That's not really solving your slope issue. It's creating a workaround to avoid solving the problem.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Slope issues

Post by s-ol »

Jasoco wrote:
AlexsSteel wrote:Don't worry, i solved it.

Image
That's not really solving your slope issue. It's creating a workaround to avoid solving the problem.
I'd say thats a pretty legit way of doing slopes with box2D

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests