#Precise sprite collisions…without the default methods

1 messages · Page 1 of 1 (latest)

late oriole
#

For my custom hitbox system, I disable Game Maker’s default collision checks (all you have to do is turn on the physics world!) and supplement them with my own, which works shockingly well. I have several different shapes like circles, AABB’s, lines, etc.. but I realized I don’t have an equivalent for precise sprite collisions. Is there potentially a way to get two sprites and simulate place_meeting with them somehow?

ripe tendon
#

the fastest, most optimal solution, would be to use place_meeting with precise masks heh. otherwise you will need to either cache the pixels into truth tables and compare cells as pixels, or divide them into complex arrangements of shapes and test in-shape functions

#

you could also test pixel color but thats extremely slow

#

any specific reasons you dont wanna use the built in functions?

late oriole
#
#

Which basically means I have to only check for collisions whenever a “game” frame runs

#

Idk what truth tables are but I’m guessing that would be super slow right

ripe tendon
#

so you're turning off the collision events by flipping on physics, and then using your own collision functions on each of your own game steps? why not just use the built in collision functions like place_meeting, instance_place, etc. they only run when you call them and you can't make collisions faster than gm's built in functions

late oriole
#

Part of it is I can have multiple hitboxes per instance too

ripe tendon
#

you can do that using mask_index

#

like this is valid:

var hold = mask_index;
mask_index = check_a;
if (place_meeting(x, y, obj) == true) {
}
mask_index = check_b;
if (place_meeting(x, y, obj) == true) {
}
mask_index = hold;```
#

if you're looking for performance benefits then definitely use what gm offers. if yer looking to learn and dont mind the performance costs, then thats a whole other radical thing

#

(cannot overstate it tho, its not possible to make collisions in gm better or faster than what gm has built in)

late oriole
#

You gave me a great idea

#

Can you like, repeatedly turn on/off physics per frame if need be

#

Like turn it off just to check a single place meeting and then turn it back on immediately

ripe tendon
#

not sure about that but its not something i'd do personally

#

i would only turn physics on for a single thing and that would be because i am using the built in physics system

late oriole
#

True yeah

#

I just wish there was a better way to turn off automatic collisions

ripe tendon
#

collisions do not happen automatically though

#

collision checks are only made if you give an instance a collision event or you call a collision function

late oriole
#

I know they get skipped if two

#

Yeah

ripe tendon
#

so if you only check for collisions, using the step event and collision functions (not the collision events), when your game updates then you're already winning

late oriole
#

Yeah, you’re right

#

I am super proud of this hitbox system regardless though, even if I didn’t need to do it I feel like I learned a lot

ripe tendon
#

oh you absolutely should be haha

late oriole
#

I got it reasonably fast too somehow

ripe tendon
#

nice

late oriole
#

I might’ve just figured out an idea based on what you just told me

#

You can set the bounding boxes of instances during gameplay now can’t you

ripe tendon
#

no

late oriole
#

I thought you could, I’m probably remembering something wrong

ripe tendon
#

bboxes are just boxes that surround the collision mask, regardless of shape its always the tightest possible rectangle around the mask. except when the mask is precise, then the bbox is the full size of the sprite image

late oriole
#

Ohhhh ok, I see what I was thinking of now

#

sprite_set_bbox

ripe tendon
#

ah yeah, that changes the bbox on the sprite on an asset level if i recall, generally dont wanna do that

late oriole
#

Yeah, I figured

#

Unless you’re doing some really crazy hacks

#

I’m trying to figure out a potential way to combine my hitbox system with more of GM’s basic behaviors

#

I was thinking maybe changing the instances’ masks to AABB’s that would fit around where their hitboxes are as a simple broad phase

ripe tendon
#

i mean thats what the bbox is by default; are you talking about for precise masks tho?

late oriole
#

Not for this particular thing

#

I mean more like

#

Say I have multiple hitboxes for an instance right

#

The idea would be to get the area surrounding all of them, and then somehow stretch the instance’s mask over them to act as a broad phase

#

Then within the actual collision event if I need to for the instances, I can run a script that properly checks their hitboxes to see which ones actually collide

#

The broad phase is what I’ll need to figure out, and then I think I can figure out the rest

ripe tendon
#

youre using the collision event and your custom collision system?

late oriole
#

Kinda meshing them together yeah

ripe tendon
#

👀

late oriole
#

Though this is just me spitballing how to improve it in a future iteration

#

If I can do that without, say, having to change the x and y positions mid collision event to make it work or something I’d be golden

ripe tendon
#

well, like i said, the best possible improvement is to just cycle through mask_index and using the built in collision functions and just all together ignore the collision events heh

#

since youre working on a time step solution, you prolly got something like:

if (update == true) {

}```or something similar. you just use place_meeting or instance_place or whatever in that update