Hit detection respects priority & groundedness #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I copied in some code I've written elsewhere and modified it a bit to make enemies more thorough in detecting hits. The most notable change is that enemies will respond better when they're intersecting multiple hitboxes. Specifically, it will select the highest-priority hitbox that's capable of hitting the enemy (i.e. doesn't belong to Player 5). I've also made it so that grounded-only and aerial-only hitboxes will only be able to connect if the enemy has the necessary
free
value. So now if someone were to make an attack that sends grounded and aerial opponents at different angles, by overlaying one grounded-only and one aerial-only hitbox over top of each other, that move would now interact with enemies correctly. This should also ensure that sweetspots and sourspots will connect the same way they would against a normal player. Also, while I haven't observed this being a problem, I'd assume that the old system could give an enemy de-facto invincibility if they're intersecting a friendly hitbox, since thehit_id = instance_place(x,y,pHitBox);
could just return that friendly hitbox. I'm not sure how likely or unlikely that would be, since I don't know how GML decides which instance to return when there are multiple intersecting objects. Another small tweak is that the enemy no longer checks for hitbox collisions at all when hit_lockout > 0. From what I could tell from the code, it looked to me like hit lockout made the enemy check for hitbox collisions but then just throw them out.I made sure that my code only runs when the initial check detects a hitbox, though, so this should only ever impact performance on the frame that an attack connects. It's also organized such that it checks collision last, preferring to eliminate potential hits through any of the less expensive checks first if possible.
I didn't make matching changes to the destructible terrain article. I figured that people probably won't care as much if it's harder or easier than normal to sweetspot destructible terrain as opposed to an enemy, and the grounded/aerial distinction is pretty meaningless for a terrain object.
One other thing I did that I'm not 100% sure about is adding support for Qua Mario's "only hit below" hitbox variable (line 780), which just makes it so the hitbox won't connect unless it's hitting the very top of the hurtbox. I tested this in-game to see how it felt, and I had mixed feelings about it. It doesn't affect combat against the short grounded enemies much. It made it harder to accidentally Stomp on the guards in the city, which I thought was nice. It also made combat against Rocko more engaging, since shorter jumps could no longer hit him. However I found that it made fighting the flying enemies way harder, and kind of annoying, since getting above them is so difficult. As a compromise, I made it so that it only respects the "only hit below" variable when the enemy is grounded. I'm not totally confident in this solution though. I also don't know if it might be a bit self-important of me to put in a compatibility check that only my character is likely to use 😅 You can do whatever you want with that check - comment it out, remove the grounded-only check, anything. I don't have strong opinions on the matter.