Legacy GM Faster Precise Collisions

RyanC

Member
Hi All,

I want to implement precise collisions for my spider looking robots because the collsions are really bad with a normal shape.

Would it be possible to set the collision shape as a rectangle and then only check precise collision when the rectangle collision has be triggered?
 

Simon Gust

Member
I believe it works if you don't use functions like place_meeting for the rectangle collision.
->
first, use rectangle_in_rectangle, and once that returns greater than 0, use place_meeting.
you just have to loop through every collider instance, (don't know if instance nearest is good for this).
 

GMWolf

aka fel666
Hi All,

I want to implement precise collisions for my spider looking robots because the collsions are really bad with a normal shape.

Would it be possible to set the collision shape as a rectangle and then only check precise collision when the rectangle collision has be triggered?
GM already does this by default.

I had a set of scripts that would use quadtrees for collision checking. On a 1080p sprite, It would remain more efficient until the accuracy was of about 8 pixels. Any lower and GMs native implementation was faster.
But on normal sized sprites, Its really not worth it.

I would suggest you create series of hit boxes to cover your sprite with.
 

RyanC

Member
I just switched to precise collision expecting the debug module to show an increase on performance hit and it appears that using a rectangle or precise collision makes nearly no difference at all, when using the built in fast
collision system.

Very impressive! how is that even possible?
 

GMWolf

aka fel666
I just switched to precise collision expecting the debug module to show an increase on performance hit and it appears that using a rectangle or precise collision makes nearly no difference at all, when using the built in fast
collision system.

Very impressive! how is that even possible?
The fast collision system makes use of space partitioning, such that the collision code is not being run when two objects are away from each other.
Another thing to consider is that a single instance of precise collision wont do your game any harm, but rather when you start building up the number of precise collisions going on.
 

kupo15

Member
The fast collision system makes use of space partitioning, such that the collision code is not being run when two objects are away from each other.
Another thing to consider is that a single instance of precise collision wont do your game any harm, but rather when you start building up the number of precise collisions going on.
when you say building up thee number of collisions that's only if a lot of precision objects overlap? Like if you have 20 precision objects on screen but none overlap then no checking is occurring so its fine? Only if all 20 overlap at the same time will there be more of an impact?

I didn't know GM does selective checking like this automatically, that's cool. Isn't there still some use for setting up your own checks to limit unnecessary checks? For example when throwing out an attack there is no reason to have your hitbox check with your player mask since you can't hurt yourself. Wouldn't it still be more efficient to throw a

if not_your_hitbox
place_meeting(obj_hitbox)

Would this would bypass GM auto checking the collision when they overlap and cause no checks?
 

GMWolf

aka fel666
Like if you have 20 precision objects on screen but none overlap then no checking is occurring so its fine? Only if all 20 overlap at the same time will there be more of an impact?
yes, from what I can gather, GM first uses some for of spacial partitioning (BVH, quads, hashes...), Then performs a bounding box check, before doing the precision check. (This is from fragments of info i got from the forums, so im just guessing).

Isn't there still some use for setting up your own checks to limit unnecessary checks?
Not really, GM does a great job already.
if not_your_hitbox
place_meeting(obj_hitbox)
At this point, It changing the logic: You are no longer relying on spacial information alone, but are introducing extra variables GMengine would have no way of knowing about.
So it depends on your game play.
 

kupo15

Member
yes, from what I can gather, GM first uses some for of spacial partitioning (BVH, quads, hashes...), Then performs a bounding box check, before doing the precision check. (This is from fragments of info i got from the forums, so im just guessing).
Pretty neat!

Not really, GM does a great job already.
My quote goes with the example I provided lol I would hope that by throwing this condition GM won't even check for spatial proximity instead of checking for spatial proximity and then skipping the precise part. I would assume that the spatial check only occurs on place_meetings that are actually active
 

GMWolf

aka fel666
My quote goes with the example I provided lol I would hope that by throwing this condition GM won't even check for spatial proximity instead of checking for spatial proximity and then skipping the precise part. I would assume that the spatial check only occurs on place_meetings that are actually active
well yes, when you call place_meeting ,GM does collision code.
If you dont call it, then it doesn't do the check.

same with events, if you dont have collision events, GM wont compute them.
 

kupo15

Member
That's what I figured. So a check like this would be helpful if you had a game with a ton of objects checking collision.
 
Top