Collision Behavior

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
owlkatraz
Prole
Posts: 1
Joined: Wed Dec 24, 2014 8:54 am

Collision Behavior

Post 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
Last edited by owlkatraz on Thu Dec 25, 2014 7:16 am, edited 2 times in total.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Collision Behavior

Post 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
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Collision Behavior

Post by Jasoco »

If you want simple AABB collision, kikito's Bump library is really good for that.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], MrFariator, Semrush [Bot] and 150 guests