nesdev.com
http://forums.nesdev.com/

Collision check when swinging a sword
http://forums.nesdev.com/viewtopic.php?f=2&t=15998
Page 1 of 1

Author:  DRW [ Mon May 29, 2017 5:24 am ]
Post subject:  Collision check when swinging a sword

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?

Author:  FrankenGraphics [ Mon May 29, 2017 6:19 am ]
Post subject:  Re: Collision check when swinging a sword

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'.

Author:  DRW [ Mon May 29, 2017 6:37 am ]
Post subject:  Re: Collision check when swinging a sword

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.

Author:  dougeff [ Mon May 29, 2017 8:31 am ]
Post subject:  Re: Collision check when swinging a sword

I used the position of the actual sword sprites...which would be several (2-3) small hitboxes.

Author:  Sumez [ Mon May 29, 2017 8:47 am ]
Post subject:  Re: Collision check when swinging a sword

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.

Author:  Dwedit [ Mon May 29, 2017 9:44 am ]
Post subject:  Re: Collision check when swinging a sword

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)

Author:  tepples [ Mon May 29, 2017 10:11 am ]
Post subject:  Re: Collision check when swinging a sword

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.

Author:  Sumez [ Mon May 29, 2017 10:42 am ]
Post subject:  Re: Collision check when swinging a sword

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.

Author:  Bregalad [ Tue May 30, 2017 2:33 am ]
Post subject:  Re: Collision check when swinging a sword

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.

Author:  na_th_an [ Thu Jun 01, 2017 12:29 am ]
Post subject:  Re: Collision check when swinging a sword

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".

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/