While going through my course I got to the point where we implement player combat. Even though the course is clear and easy to understand I do have a problem with hit registration. I’ve implemented the code as it was written in the lecture but I’ve noticed that my hitbox is not registering some swings that visibly hit the target (same attack sometimes hit, sometimes miss, even though the character is in the same place). Could you help me out with this?
This is how it looks on my end, you can see that there are gaps big enough to miss the registration.
Hi John,
Can you add this post to the course Q&A please. I will take a look but I don’t check here often and if added the Q&A, I can see the specific lecture and access the relevant source for checking.
The hit system is only designed to register the first hit box for each enemy that is hit and subsequent boxes are supposed to be ignored to prevent multiple hits so the same enemy. If you have forgotten to clear this collection, only the first hit would be registered.
This would be my first guess but a screenshot itself doesn’t work. I’d need to see the actual code.
The gaps in your debug shapes look like the trace is only sampled once per frame, so a fast swing can skip over the target between two samples. A common fix is to sweep from the previous position to the current one, or to add a few substeps per frame. Also check that the frame rate in the editor is not dropping, since a low frame rate makes the gaps bigger.
That is reasonable but given the size of the collision for the boss in this course, it doesn’t occur. A sweep would be a better solution for smaller characters.
Thanks for sharing the comparison screenshots, that gap in the debug shapes is really clear. Checking the sweep approach sounds like a sensible next step, especially for fast swings where a single trace can miss between frames.
Hello, and sorry for not posting a reply. I was able to fix it using sweep from previous to current position, had some challenges there but it worked as expected. Also, thanks to all of you willing to help!