This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Collision check when swinging a sword

Collision check when swinging a sword
by on (#196858)
How do old games like "Link's Awakening" or "Final Fantasy Adventure" do the collision check when the hero swings his sword in an arc? Especially the diagonal version.

Usually, collision checks are done by declaring a rectangle for the object and seeing whether the rectangles would overlap.

So, in a diagonal direction, do they simply put a rectangle over the whole sprite, so that a collision also registers even if the monster only touched empty space?
Or do they use various smaller rectangles, located diagonally along the sword, doing more than one collision check?
Or is there any other method?
Re: Collision check when swinging a sword
by on (#196861)
This is pure speculation, but what if they used small hit maps? a table of say 8x8 or 16x16 y/n entries, which corresponds to the current frame. That would be very precise. (the resolution doesn't have to be 1:1 to pixels. 1:2 would be precise enough, i think).
Note that you only need to call these checks during a brief attack, only when an enemy is within a first conditional range, and only for as long as the returns are 'no'.
Re: Collision check when swinging a sword
by on (#196862)
Yeah, that's what I mean with a lot of small rectangles.

I'm still asking myself whether this is how it actually worked in "Zelda IV" or if they used a different technique.
Re: Collision check when swinging a sword
by on (#196871)
I used the position of the actual sword sprites...which would be several (2-3) small hitboxes.
Re: Collision check when swinging a sword
by on (#196872)
I'm pretty sure Zelda 4 is just a rectangle that covers most of the animation, but that's just speculation on my part. A speedrunner would probably know the exact details (maybe one of these guides covers it: https://www.speedrun.com/ladx/guides )

The thing is, you COULD try for a more exact 1:1 relation between graphics and collisions, but it wouldn't really serve any purpose. It would feel the same to the player. As a general rule, you want hitboxes to always work in the player's favor - ie. a bit smaller than your sprite when taking damage, but possible a little bigger when dealing damage - I'm fairly certain Link's Awakening does this, making sure you never get the feeling that you should have hit something when you didn't.
Trying to make game logic more "realistic" rarely means better gameplay, and quite often the exact opposite. It's one of those quirks that define a lot of "retro" games.


I'm sure you could also find a lot of games that just check for collisions along a single vertical or horizontal line rather than a rectangle. Makes detections twice as fast, and can work just as well if you place it right.
Re: Collision check when swinging a sword
by on (#196880)
How about just testing three points (origin, middle, tip) against a slightly enlarged hitbox of the enemy?

(fun fact, testing a point against an enlarged hitbox is equivalent to doing a naive rectangle check)
Re: Collision check when swinging a sword
by on (#196886)
Sumez wrote:
The thing is, you COULD try for a more exact 1:1 relation between graphics and collisions, but it wouldn't really serve any purpose. It would feel the same to the player. As a general rule, you want hitboxes to always work in the player's favor - ie. a bit smaller than your sprite when taking damage, but possible a little bigger when dealing damage

That would be better for a game with only player-against-environment (PvE) encounters than a game that also includes player-against-player (PvP) encounters. The increased precision expected of PvP is why the Super Smash Bros. fighting games use a "thick line segment" hitbox shape, defined as the set of points within a radius of a line segment.

  • If the lines cross, it's a collision.
  • Otherwise, both of one line segment's points are on one side of the other line segment. Forget the far point, and now you're down to a point-line proximity test.
  • If the point is between the perpendiculars of the endpoint, use a distance-from-line test.
  • Otherwise, use a distance-from-point test.

A simplified form of this, as a test between a circle and axis-aligned line segment, is used for collisions between explosions and balloons in Thwaite and between the ball and paddle in "ZapPing" in Zap Ruder.
Re: Collision check when swinging a sword
by on (#196892)
PvP gameplay is a completely different size in many ways, really. The biggest challenge in making a fighting game is obviously balancing completely different styles of attacks in a way that never seems unfair to either player, and that goes way beyond just hit- and hurtboxes (general character design as well as attack type priorities, etc.). I don't think that's what OP was going for though.
Re: Collision check when swinging a sword
by on (#196929)
In my game I simply have a set of variable for each of the 4 corners of a collision box, and by default they're set to some values. When the player is in its "attacking" pose I overwrite them with other values, depending on the direction the player is facing.
Re: Collision check when swinging a sword
by on (#197075)
I simply moved a small hitbox, in some cases just a pixel at the tip of the sword, using a precalculated set of offsets syncronized with the animation. Using chibi proportions this works well enough, as the sword is not very long and is of course not longer than enemies or destructible stuff, meaning that you won't miss something going between the player and the "hotspot".