Page 1 of 1

Collision Behavior

Posted: Wed Dec 24, 2014 9:02 am
by owlkatraz
Hi. Super new to Love, Lua, etc. Trying to make a first game and realized I had to implement collision. Looked around a bit and decided to go for a simple AABB implementation.

However, depending on the angle that my rocket hits a star, it will "slide" along the surface of the star very shakily before bouncing back the opposite direction.
edit: fixed

Re: Collision Behavior

Posted: Thu Dec 25, 2014 3:31 am
by Azhukar
Your rocket collides with more than 1 star simultaneously, each time negating its angle.

Write "break" after line 76. That means after you detect a collision and correct it, you call "break" and stop checking for more collisions by escaping the for loop.

Code: Select all

for i, curStar in ipairs(starList) do
		if(CheckCollision(rocket.minx, rocket.miny, rocket.maxx, rocket.maxy, curStar.x, curStar.y, curStar.x + curStar.width, curStar.y + curStar.height)) then
		CorrectCollision(rocket.minx, rocket.miny, rocket.maxx, rocket.maxy, curStar.x, curStar.y, curStar.x + curStar.width, curStar.y + curStar.height)
		break
	end
end

Re: Collision Behavior

Posted: Thu Dec 25, 2014 1:48 pm
by Jasoco
If you want simple AABB collision, kikito's Bump library is really good for that.