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?
#Precise sprite collisions…without the default methods
1 messages · Page 1 of 1 (latest)
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?
Gaffer On Games
Introduction Hi, I’m Glenn Fiedler and welcome to Game Physics.
In the previous article we discussed how to integrate the equations of motion using a numerical integrator. Integration sounds complicated, but it’s just a way to advance the your physics simulation forward by some small amount of time called “delta time” (or dt for short).
But how ...
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
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
Part of it is I can have multiple hitboxes per instance too
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)
A little of both yeah
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
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
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
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
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
oh you absolutely should be haha
I got it reasonably fast too somehow
nice
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
no
I thought you could, I’m probably remembering something wrong
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
ah yeah, that changes the bbox on the sprite on an asset level if i recall, generally dont wanna do that
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
i mean thats what the bbox is by default; are you talking about for precise masks tho?
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
youre using the collision event and your custom collision system?
Kinda meshing them together yeah
👀
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
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