Pixel colision

Monkey Forums/Monkey Programming/Pixel colision

Josepho(Posted 2012) [#1]
Hi there, im a bit new here, i have been looking for collision functions in monkey but i didnt have success on that, do i have to code them by myself?

Do you recomend me any simple 2d framework that have 2d colision functions?

If i have to code by my self, how to start making a pixel colision? Anyway to check the pixels of an image?

Many thanks !


Paul - Taiphoz(Posted 2012) [#2]
It's funny you asked that I have an active discussion on face book with a few fellow monkey developers, talking about this very subject.

I agree monkey needs a good solid working collision function much like those found in B3D or Max.

Something like ImageCollide:bool(image1,x,y,f,sx,sy,r,image2,x,y,f,sx,sy,r) would be nice.

Mark seems to be slow on supporting individual targets with stuff that wont work on them all so I can only assume this is the reason we dont have something like this, one of the targets must suck when it comes to collisions.

I cant think of which platform it might be that's holding this addition back.

@ josepho , In the mean time, you have two working options, one is a function to check if two rectangles are overlapping, and the other is a simple distance check for more circular objects.

You can use more than one smaller rectangles and cover a sprite or game object with a number of rectangles to get a bit more accuracy but the more you add the higher the overhead.

possibly some of the smarter coders will be able to show us some better solutions.


slenkar(Posted 2012) [#3]
pixel collision code is quite slow,
there is a polygon collision library in the code archives,
http://monkeycoder.co.nz/Community/posts.php?topic=353

experiment with it and then create an editor to define polygons for each image you have


Paul - Taiphoz(Posted 2012) [#4]
Yeah that's another good idea, something I did recently in my little vecotor module , I never thought about actually using it as a ghost collision system tho.

I am wondering which would be more efficient, wrapping a sprite with a polygon which could have lot of points to manage, or covering it with a collection of rectangles, which could use a lot less.

I think for complex static objects wrapping them in a polygon would be the best option, the point wont ever need to move, but for small less complex objects, overlay of rectangles might be better.

its all theory tho until tested, if I would any good ad making tools I might consider having a crack at this to make the whole process easier.


Josepho(Posted 2012) [#5]
I finnally didnt use perpixel col in my project, will try polygon collision instead, many thanks


zoqfotpik(Posted 2012) [#6]
Seems like this would be a good job for BSP trees.

But I'm skeptical as to whether real pixel-perfect collision is necessary. Seems like you could use rectangles and drastically cut down the number of checks in various ways and the player would never know it.


Gerry Quinn(Posted 2012) [#7]
Rectangle is usually the first check anyway, you should only be doing accurate checks when you have cheaply established that objects are close together.