Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / 2d Rectangle Collision

Author
Message
HeavyAmp
18
Years of Service
User Offline
Joined: 25th Oct 2006
Location: Castle in the Sky!
Posted: 2nd Apr 2007 21:06
Ive Been trying to Make my own collision for my 2d game. Ive got my Circle collision Working. That was pretty easy but oddly enough the rectangle collision is giving me Some troubles.

Ive figured out how to create a turning rectangle I just cant figure out how to detect if an object(point) goes inside it. Its easy enogh if the rectangle is straight. You just use the same Code as in a button. I also made some code to detect if an object is inside a perfect diamond. IE the angles are 45 degrees. What I'm after is a way to detect if something is inside a rectangle no matter which angle the Rectangle is on. Help would be much appreciated.

Heres My Code So far:



In theory, there is no difference between theory and practice. But, in practice, there is.
Crit
18
Years of Service
User Offline
Joined: 24th May 2006
Location:
Posted: 3rd Apr 2007 02:25
I found this code by IanM in the codebase. It finds if a point is in a triangle. You could think of your rectangle as two triangles.

` This code was downloaded from The Game Creators
` It is reproduced here with full permission
` http://www.thegamecreators.com

HeavyAmp
18
Years of Service
User Offline
Joined: 25th Oct 2006
Location: Castle in the Sky!
Posted: 3rd Apr 2007 02:44 Edited at: 3rd Apr 2007 02:55
Thanks Crit, Ill have a shot at it.

Ahh,I see, it takes the point you are wanting to see collide, then the three corners of the triangle. All those floats had me scared for a minute.

In theory, there is no difference between theory and practice. But, in practice, there is.
Crit
18
Years of Service
User Offline
Joined: 24th May 2006
Location:
Posted: 3rd Apr 2007 05:32
After some testing, that function would work well, but not perfectly. There are a few dots inside the shape that don't register. The chances are pretty slim that the collision would test against those points, but it's something to be aware of. I attached a picture to show what I mean.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-25 20:44:49
Your offset time is: 2024-11-25 20:44:49