Simple, lightweight, general purpose collision detection

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by Taehl »

Another update to my demo: Boxes are now randomly-sized (to show that rectangles aren't slower than squares, and just to look more interesting), and ability to dynamically enable/disable their physics.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by vrld »

Looks neat. Three bugs though:
One: When I stand next to a box, so that the player and the box are touching, and the box is touching a wall, the player can't jump anymore.
Two: When I jump onto one box and then run off one side, the box will slide into the same direction.
Three: Things are intersecting:
trapped_in_boxes.jpg
trapped_in_boxes.jpg (5.47 KiB) Viewed 1982 times
As for optimization, I think a SpatialHash might be easier to implement than a QuadTree and might even be faster in some cases.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by Taehl »

1) That's due to me using a quick'n'dirty way of telling if the player is standing on the ground. With a tweak or two, it'll be fixed.
2) ... I don't think I get what you're saying. Wouldn't that be physically correct?
3) They only intersect if you stack 3 or more shapes. But you know what? If you need to stack stuff that badly, you should be using love.physics anyway. If you just need a few simple pushable boxes or enemies that can jump and fall, I think this will do the trick.

In other news, I'm currently adding support for mobile static shapes (read: moving platforms).
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by kikito »

vrld wrote:I think a SpatialHash might be easier to implement than a QuadTree and might even be faster in some cases.
I agree that it will be easier to implement. I can't imagine how it could be faster, tough.
When I write def I mean function.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by Taehl »

Updated the fizz demo again. Now dynamics can ride moving statics! I've also added some stuff to let you mess around more: Better box-spawning controls, a box that follows the cursor (so you can shove stuff around), and the ability to add/remove platforms. I also made the player-box move in a more traditional platformer style (better sliding, air-control, hold-the-button-to-jump-higher, and the ever-popular butt-stomp).

EDIT) And crouching. And it'll be squished / forced to crouch if it's touched both on top and on bottom.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by vrld »

Taehl wrote:... I don't think I get what you're saying. Wouldn't that be physically correct?
I would expect it to move into the opposite direction.
kikito wrote:I agree that it will be easier to implement. I can't imagine how it could be faster, tough.
For inserting shapes into a quad tree, you have to do tree traversal and possibly rebuild part of the tree. Same thing if you move stuff around in the quad tree, especially if the object moves to another quadrant that is higher up in the hierarchy. With a spatial hash doing both takes constant time.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by TechnoCat »

vrld wrote:Same thing if you move stuff around in the quad tree, especially if the object moves to another quadrant that is higher up in the hierarchy. With a spatial hash doing both takes constant time.
Won't you still have to do a linear search in the index to find it and move it?
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by Taehl »

This excellent tutorial was mentioned in another thread, and will be invaluable to anyone trying to make physics.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by TechnoCat »

Taehl wrote:This excellent tutorial was mentioned in another thread, and will be invaluable to anyone trying to make physics.
It was mentioned in this thread too actually. http://love2d.org/forums/viewtopic.php? ... 315#p24797
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Simple, lightweight, general purpose collision detection

Post by vrld »

Update on HardonCollider:

Some errors were fixed, a TODO eliminated (the one about the translation direction) and a few things were easier. I also started to document the whole thing:
http://vrld.github.com/HardonCollider/

There will be a tutorial featuring how to write a simple game using HardonCollider soon.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Post Reply

Who is online

Users browsing this forum: No registered users and 57 guests