Precise Collision Test

Hi Everyone

Has anyone ever had problems with collision tests between circles/squares or irregular shaped objects?

What I mean by collision is precise contact between each object. I.e. when the objects touch each other exactly (not with a gap in between).

Any does anyone know any good tutorials that I can check out to get some ideas :slight_smile:

Thanks in advance :thumb:

There ae possible ways that you can set this up. They all revolve around two irregular shapes trying to hitTest one another I fear. My personal suggestion to you is to actually do some multiple tests.

Use the this.shape.hitTest(this.shape2._x, this.shape2._y, TRUE);

Except… On shape2… You might want to use a multitude of points. I would suggest sticking around 4-5 points.

But… What if your shape is extremely irregular… this is where some of my math conscience comes in… if I had an art program on the computer I’m sitting in… I would show you what I am talking about it terms of images. But…You’ll have to make do with what I can explain until I do get near such a computer.

You will want to have 8 points defined on each shape… 8 points that extend the same distance out from the shape the same distance… Except one in the cardinal directions…

shape1points[]
shape2points[]

Now… Each point should be laid out like such…

––*

–O--

––*

Where O is the center of the shape and the * are the points around the shape’s center. They should extend at most 5 pixels out. Now… With these points… You will want to test each one’s x and y locations and compare them to the center of the other irregular shape’s center point… Whichever point is the closest… it will use a set list of 5 points along that side of the irregular shape to find a specific point that will touch the other iregular shape.

If you assign 4 test points for every * that’s around the center of the irregular shape… You will get roughly 32 points of possible location to hitTest with. But sicne they all aren’t running at the same time… Only the 4 that are closest to the other shape you are trying to hit… that means that you are using minimal computer resources as well…

I hope this has helped you out in someway shape or form… If you need more info or need me to elaborate more into this… Just e-mail me.

Thanks for your help Marz :), got me a bit confused.

Don’t worry about it. I think I figured something out.