Collision Resolution Problems - NEVER HEARD THAT ONE BEFORE

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
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Collision Resolution Problems - NEVER HEARD THAT ONE BEFORE

Post by Kingdaro »

okay so uh

i'm at a complete loss right now

this is probably the fourth time i've attempted something like this, i look at examples and follow tutorials but i still can't manage to get it right. i've even in the past tried hardoncollider and that still was extremely buggy.

Code: Select all

function playerCollision()
	local colliding = 'none'
	for i,v in pairs(gWorld) do
		local c1, c2, c3, c4 = 
		player.x <= v.x+50,
		player.x+50 >= v.x,
		player.y <= v.y+50,
		player.y+50 >= v.y

		if c1 and c2 and c3 and c4 then
			local diffX = player.x - v.x
			local diffY = player.y - v.y
			colliding = '\nx: '..diffX..'\ny: '..diffY

			if math.abs(diffX) > math.abs(diffY) then
				if diffX < 0 then
					player.x = v.x-50
				else
					player.x = v.x+50
				end
			else
				if diffY < 0 then
					player.y = v.y-50
					player.yvel = 0
				else
					player.y = v.y+50
				end
			end
		end
	end
	player.collisionState = colliding
end
this is my player collision function, the colliding variable was only for debugging. gWorld is a table of boxes each 50 by 50, the player is 50 by 50 and if you haven't guessed player.yvel is the player's downward gravity-effected velocity.

the problem is that when you jump while moving against the box, the player jumps up on top of the box without sliding off it's edge and into the air, and I'm unable to jump when the player sits on top of the box.

love file: http://dl.dropbox.com/u/8005323/lua/lov ... thing.love
Last edited by Kingdaro on Thu Apr 26, 2012 7:19 pm, edited 1 time in total.
User avatar
sanjiv
Citizen
Posts: 88
Joined: Mon Feb 27, 2012 5:11 am

Re: Collision Detection Problems - NEVER HEARD THAT ONE BEFO

Post by sanjiv »

Your love file didn't run for me.

Could you post the logic of what you think your code is doing? I.e. Could you describe the process in words?
the problem is that when you jump while moving against the box, the player jumps up on top of the box without sliding off it's edge and into the air, and I'm unable to jump when the player sits on top of the box.
I don't quite understand what you're saying. How should the player normally move? And how is the player moving instead?
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Collision Detection Problems - NEVER HEARD THAT ONE BEFO

Post by Kingdaro »

the file didn't run? did it give any kind of error?

and i'll try to rephrase the issue, when I'm moving against the box, the player goes up and stops at the top of the box instead of continuing to go up, as if stepping over the block like a stair instead of actually jumping over it. not being able to jump while on top of a block seems pretty self explanatory, and I'm not even checking if the box is on the ground so I have no idea what's happening there.

after the player is done moving, this function is called and it goes through all of the boxes in the world, and it uses the algorithm from http://silentmatt.com/rectangle-intersection/ <--this demo to find a collision. if it's inside of the box more on the Y side than the X side, it resolves the collision on the corresponding X side, checking to see if the difference in positions is greater or less than 0 to know which side to resolve. repeat the process with the Y side if it were inside more on the X side than the Y side.
User avatar
sanjiv
Citizen
Posts: 88
Joined: Mon Feb 27, 2012 5:11 am

Re: Collision Detection Problems - NEVER HEARD THAT ONE BEFO

Post by sanjiv »

The error message that shows when I run your love file is
Error

main.lua:2: attempt to call field 'setDefaultImageFilter' (a nil value)

Traceback

main.lua:2: in function 'load'
I'm still not sure what you're saying the problem is. Do you

1. Start on top of a box.
2. move towards the edge of the box
3. get stuck at the edge, instead of just going straight over?
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Collision Detection Problems - NEVER HEARD THAT ONE BEFO

Post by Kingdaro »

well firstly your problem is that you're not using 0.8.0 :P

and secondly, no, that's not the problem, sorry it's so hard to describe, i'll make a gif or something.

gif isn't going so well, maybe you'll be able to see the problem after you get 0.8? if you don't see the box keep going right.
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Collision Detection Problems - NEVER HEARD THAT ONE BEFO

Post by Ellohir »

You should have explained better. For anyone who tries: The "A" is the jump button.

The problem is that, from the ground, the ball jumps a distance of 3 times a box. But coliding with the box edge (pushing against the box), it jumps just to the top of the box and stays in top of the box. Not higher as expected.

I guess it's a bug from the collision resolution, but haven't looked into it yet.
MasterShizzle
Prole
Posts: 3
Joined: Mon Apr 16, 2012 10:58 pm

Re: Collision Resolution Problems - NEVER HEARD THAT ONE BEF

Post by MasterShizzle »

The problem is your collision handling.

When you jump while pressing the direction buttons (right, for example) into the side of the box, when you get to the top of the box you're moving diagonally up and to the right. The bottom-right corner of the player's box is catching the top-left corner of your box obstacle. Since they only catch by one pixel, then diffX is equal to diffY and it defaults to the vertical collision handling, which thinks your player just landed on top of the box and so it sets your y-speed to be 0. That's why you stop instead of sliding by.

You could either put in a bias toward horizontal resolution of collisions (diffX >= diffY, instead of just diffX > diffY) or you could put in different routines based on if the player is moving upward or downward.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest