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
collision minus the physics
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- hertzcastle
- Party member
- Posts: 100
- Joined: Sun Jan 04, 2009 4:51 pm
- Location: brighton, uk
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: collision minus the physics
You don't, when they have no mass they are considered static structures (like walls).
- hertzcastle
- Party member
- Posts: 100
- Joined: Sun Jan 04, 2009 4:51 pm
- Location: brighton, uk
Re: collision minus the physics
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
thanks!x
Re: collision minus the physics
Use AABB (Axis Aligned Bounding Boxes)
Ill share my function
Example:
Example File: http://nerdthree.com/hosting/coltest.love
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
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
Re: collision minus the physics
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.
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.
- hertzcastle
- Party member
- Posts: 100
- Joined: Sun Jan 04, 2009 4:51 pm
- Location: brighton, uk
Re: collision minus the physics
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
feature request???
x
- hertzcastle
- Party member
- Posts: 100
- Joined: Sun Jan 04, 2009 4:51 pm
- Location: brighton, uk
Re: collision minus the physics
p.s. thanks for the code mike! really helpful, just playing with it now.
Re: collision minus the physics
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.
-
- Party member
- Posts: 215
- Joined: Sun Jan 18, 2009 8:03 pm
Re: collision minus the physics
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.
Who is online
Users browsing this forum: No registered users and 226 guests