collision minus the physics

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
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

collision minus the physics

Post by hertzcastle »

hi!
how do you use the collision callback without using physics and mass? nothing happens to my bodies when they both have no mass...
help!!!x
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: collision minus the physics

Post by bartbes »

You don't, when they have no mass they are considered static structures (like walls).
User avatar
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

Re: collision minus the physics

Post by hertzcastle »

so...how do i use collision detection then? basically i want to know when two rect shapes are overlapping, but i dont want to use the physics engine?
thanks!x
User avatar
mikembley
Citizen
Posts: 72
Joined: Wed Dec 17, 2008 5:30 pm
Location: Blackburn, UK
Contact:

Re: collision minus the physics

Post by mikembley »

Use AABB (Axis Aligned Bounding Boxes)

Ill share my function

Code: Select all

function RectangleIntersectionTest(r1, r2)
	r1.x2 = r1.x+r1.width
	r2.x2 = r2.x+r2.width 
	r1.y2 = r1.y+r1.height
	r2.y2 = r2.y+r2.height
	
	if r1.x2 < r2.x or r1.y2 < r2.y or r1.x > r2.x2 or r1.y > r2.y2 then
		return false
	else
		return true
	end
end
Example:

Code: Select all

rect1 = { x=100, y=100, width=200, height=100 }
rect2 = { x=100, y=90, width=50, height=80 }

if( RectangleIntersectionTest(rect1, rect2) ) then
     --Put collision hit test code here..
end

Example File: http://nerdthree.com/hosting/coltest.love
User avatar
Gerrit
Prole
Posts: 46
Joined: Wed Mar 25, 2009 7:40 pm

Re: collision minus the physics

Post by Gerrit »

As Mike wrote: This works only for rectangles without an angle. For everything else you need A: The physics engine or B: Hardcoded collision maps of your objects. Like a 32x32 table for a 32x32 sprite which contains a 0 for not visible pixels and a 1 for visible ones. Those maps plus the bounding box gives you a nice, pixel correct collision detection. If you know more languages then lua you can code yourself a small converter which writes the table code from the images for you :)

Will be obsolete when Löve 0.6 is released as it gives you the ability to check the transparency of a pixel. Then you can make your collisionmaps on the fly. Just if anyone is curious about how to implant collision detection without physics.
User avatar
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

Re: collision minus the physics

Post by hertzcastle »

thanks for the replies guys! seems a bit stupid not to just be able to use the collision callback for rects without using physics and having things flying all over the place :(
feature request???
x
User avatar
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

Re: collision minus the physics

Post by hertzcastle »

p.s. thanks for the code mike! really helpful, just playing with it now.
User avatar
Sslaxx
Citizen
Posts: 57
Joined: Sat Feb 14, 2009 8:54 pm
Location: Malvern, Worcs, UK
Contact:

Re: collision minus the physics

Post by Sslaxx »

I understand there may be the possibility for being able to pixel-level collision when the ability to read pixels is added, but as for being a out-of-the-box collision detection method, unlikely.
osuf oboys
Party member
Posts: 215
Joined: Sun Jan 18, 2009 8:03 pm

Re: collision minus the physics

Post by osuf oboys »

Set all the box2d bodies to sensors with non-zero mass and 0 gravity?
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.
Post Reply

Who is online

Users browsing this forum: ausboss20001, Google [Bot] and 23 guests