# Find Collision Area

2 replies to this topic

### #1 icuurd12b42

icuurd12b42

Self Formed Sentient

• GMC Elder
• 18181 posts
• Version:GM:Studio

Posted 28 July 2008 - 11:19 PM

CollisionPointIDs(id1,id2)
Determines the collision point of 2 instances
return 0 if no collision point
return 1 if collision point
you should call it on collision
it will work if the 2 instances overlap or if 2 egdes are touching (Better result)
so make sure you move them into contact with move contact solid.
sets the following instance variables for you to get the region
(Eventually set to about a 1x1 region)
__left;
__top;
__right;
__bottom;
__x is the average (center of rect)
__y is the average (center of rect)

IntersectRectIDs(id1,id2)
determines the intersecting rectangular area of 2 instances' bbox
return 0 if no intersection
return 1 if boxes intersect
sets the following instance variables for you to get the region
__left;
__top;
__right;
__bottom;
__x is the average (center of rect)
__y is the average (center of rect)

CheapCollisionRectIDs(id1,id2)
works like IntersectRectIDs(id1,id2)
but only if the 2 objects are really colliding
determines the intersecting rectangular area of 2 instances' bbox

CollisionRectIDs(id1,id2)
works like CheapCollisionRectIDs(id1,id2)
but returns the average rectangular area of the collision
from the left and top most colliding area to the righ and bottom most
does not handle multiple areas, it would combine them into a single larger one

FinerCollisionRectIDs(id1,id2)
works like CollisionRectIDs(id1,id2)
but performs 2 passes to reduce error

CollisionArrayIDs(id1,id2)
This produces a rectangular area like the other functions and also produces a collision array
it's slow

return 0 if no intersection
return 1 if boxes intersect
sets the following instance variables for you to get the region
__left;
__top;
__right;
__bottom;
__x is the average (center of rect)
__y is the average (center of rect)
__coly[] is the collision x array
__colx[] is the collision y array
__numcol is the array count... num collisions
__avgx is the average collision spot
__avgy is the average collision spot

Update

CollisionPointIDs
determines the collision point of 2 instances
return 0 if no collision point
return 1 if collision point
you should call it on collision
it will work if the 2 instances overlap or if 2 egdes are touching (Better result)
so make sure you move them into contact with move contact solid.
sets the following instance variables for you to get the region
(Eventually set to about a 1x1 region)
__left;
__top;
__right;
__bottom;
__x is the average (center of rect)
__y is the average (center of rect)

Edited by icuurd12b42, 05 May 2009 - 12:13 AM.

• 1

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button

### #2 icuurd12b42

icuurd12b42

Self Formed Sentient

• GMC Elder
• 18181 posts
• Version:GM:Studio

Posted 30 March 2009 - 04:15 AM

Update

CollisionPointIDs

It is a fast method to figure where 2 instances touch. Using a binary search and recursion method.
• 0

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button

### #3 dark_master4

dark_master4

GMC Member

• GMC Member
• 1232 posts
• Version:GM:Studio

Posted 09 August 2014 - 04:19 AM

Hey there, sorry to revive this topic but it's very useful. I was wondering if you could update it for GM:S.

• 0

My YoYoGames Marketplace (Has scripts, shaders and poker chips)

GM:Studio
Desktop Intel i5-4440 3.1ghz, 8gb RAM, NVIDIA GeForce GTX 770 2gb
Laptop AMD Athlon x64 2.1ghz, 4gb RAM, 256mb shared VRAM