Collisions?
Monkey Forums/Monkey Programming/Collisions?
| ||
What is everyone else using for collisions? |
| ||
fantomEngine works like a charm. And a lot of other stuff. |
| ||
A non framework method would be nice! |
| ||
Mostly rect collisions via hitboxes and ray casting for fast moving objects. |
| ||
Example? |
| ||
Check out Diddy's platformer example :P http://code.google.com/p/diddy/source/browse/#svn%2Ftrunk%2Fexamples%2FPlatformer |
| ||
Have no idea wots goin on Phil! |
| ||
I've just implemented SAT Separating Axis Theorem in monkey. Works for all convex shapes including circles. It was fairly easy to implement and is really quick due to the algorithms early exit. I've also implemented AABB Axis Aligned Bounding Box and Orientated Bounding Box OBB for intersection tests. I'll be posting the code soon when I have cleaned it up and made some better examples showing how to use it. I will also make it completely framework independent to allow for easier integration into your projects. There is also Box2D, this can be used for collision detection, you don't have to use the physics if you don't wan't to. |
| ||
Heres a really quick ray cast example: |
| ||
AABB collision is pretty straightforward to implement. If you want a very simple concept of collision to use, circle-to-circle collision is easy. If the distance between 2 circles is less than their combined radius lengths, then you can assume they're colliding. It's not the fastest thing in the world but it's easy to implement and can be explained in one sentence. You'll need some faster stuff later on, so look into AABB collision. There are examples for polygon, ray-cast, and pixel-mask collision in the code examples, too, but they're a bit more complicated and cost more per frame to perform checks with. |
| ||
@Nobuyuki: It's not the fastest thing in the world but it's easy to implement and can be explained in one sentence. How is that not fast? [monkeycode]dx = x1-x2 dy = y1-y2 r = r1+r2 If dx*dx+dy*dy <= r*r Then ' collided[/monkeycode] |
| ||
How come after more than a year we still don't have an official solution regarding collisions for Monkey? I know 3rd party methods do the job fine but an official solution would be better. |
| ||
I think collisions are too subjective to be included as a "thing" within Monkey. |
| ||
Well, similar collisions to blitzmax would be welcome. |
| ||
IMO there are too many different collision routines to be able to add them to Monkey. Use the right tool for the right job. For general use rectangles overlap and circle-to-circle collisions should be fine for "most" games, and they are not hard to use and are very quick. |
| ||
Without using a framework like diddy or some other, how would I proceed to having these 2 recommended collision routines placed in a module that can be used much like AutoFit or the delta timer? Erm! Yes! I need everyone to do it for me because I am lazy. :) |
| ||
2 recommended collision routines I guess you are talking about rectangles overlap and circle-to-circle(?), these are two very simple functions: [monkeycode]Function RectsOverlap:Bool(x1#, y1#, w1#, h1#, x2#, y2#, w2#, h2#) If x1 > (x2 + w2) Or (x1 + w1) < x2 Then Return False If y1 > (y2 + h2) Or (y1 + h1) < y2 Then Return False Return True End[/monkeycode] [monkeycode]Function CircleOverlap:Bool(x1#, y1#, r1#, x2#, y2#, r2#) dx = x1-x2 dy = y1-y2 r = r1+r2 If dx*dx+dy*dy <= r*r Then ' collided Return True End Return False End [/monkeycode] |
| ||
Thanks Dude! Just tested this and it works a treat! :) |
| ||
And if you want you can do Circle-to-Rects too: [monkeycode]Function CircleRectsOverlap:Bool(x1:Float, y1:Float, w1:Float, h1:Float, cx:Float, cy:Float, r:Float) Local testX:Float = cx Local testY:Float = cy If testX < x1 Then testX = x1 If testX > (x1 + w1) Then testX = (x1 + w1) If testY < y1 Then testY = y1 If testY > (y1 + h1) Then testY = (y1 + h1) Return ((cx-testX) * (cx-testX) + (cy-testY) * (cy-testY)) < r * r End [/monkeycode] |
| ||
Lovely! Thanks Dude! |
| ||
@Samah: Oh, oops. I guess I could be doing a comparison without a square root operation, huh? |
| ||
@Nobuyuki Oh, oops. I guess I could be doing a comparison without a square root operation, huh? Sqrt is eeeeeeeeevil! ;-) |