Action Hitbox

The action hitbox, like all abstract mechanical concepts, is a name given to us by MathOnNapkins in his US disassembly. This hitbox describes the current size and location of Link's sword and hammer attacks. Its routine begins at $06F5E6, and is surprisingly simple.

What even is a hitbox?

Hitboxes are very simple shapes. In fact, they're rectangles defined by 4 parameters:

For the action hitbox specifically, x and y will be relative offsets, rather than absolute. That is, all values of x and y will need to be added to Link's x- and y-coordinates to get the actual position of the hitbox.

Hitboxes are simple shapes because this cuts down on calculation time. Even modern 3D games still use basic shapes (spheres or rectangular prisms), because they are much more efficient. These games tend to use a whole lot of them to approximate more complex shapes, but the calculations are so fast and easy that this turns out to be better than a single complicated calculation.

The boxes

Within the action hitbox routine, there are several branches to determine which hitbox is used, checked in the following order:

  1. Dash hitbox
  2. Hammer and Net hitboxes
  3. Spin hitbox
  4. Sword swing and poke hitboxes

Dashing

Dashing
Direction Parameters
x y w h
Up 0 −8 16 16
Down 0 16 16 16
Left −8 8 16 16
Right 8 8 16 16

The dashing hitbox is used whenever the dashing flag at $0372 is nonzero. The direction Link is facing is used to index tables just before the routine to determine the relative offsets of the top-left corner. Regardless of Link's direction, the dash hitbox always extends 16 pixels right and 16 pixels down.

Brashing I guess

The spin hitbox is next, because it's dead simple, and because the next two sets need to be discussed together. This hitbox is used when bit7 of $3C, an address for sword control, is set.

Link's direction is completely irrelevant for the spin hitbox. This hitbox will always be 14 pixels up, 10 pixels left, and extend 44 pixels right and 44 pixels down.

Smashing and Caching and Slashing

Box?
$3C Box?
$00 false
$01 false
$02 false
$03 true
$04 true
$05 true
$06 true
$07 false
$08 false
$09 true
$0A true
$0B false
$0C false
$80+ spin

The hammer and net hitboxes point to the same branch, which is taken when the hammer is flagged (bit 1 or unused bit 3 of $0301) or the net is flagged (bit 4 of $037A). This routine shares code with slashing and poking, but there's a key difference. Believe it or not, the direction Link is facing is not taken into account.

The sword control address $3C handles spin attacks, but it also handles whether or not a hitbox should even be calculated for other sword attacks. In this case, when the value is non-negative, it indexes a table (shown to the right), for this decision. For the hammer and net, the value here is irrelevant.

The parameters of the hitbox are indexed from various tables using the X register. For the hammer and net, this index is always 0, but for sword attacks, it is a function of Link's direction and the current animation step of the attack, which is held in $3C. Once this index is calculated, both branches merge, and the rest of the routine is the same.

If direction is irrelevant for the hammer and net, how are their hitboxes actually different?

This is where two more variables come into play. They're pretty much an additional offset to x and y, so we'll call them Ox and Oy.

These offsets are constantly being recalculated, and they depend mostly on Link's current action and the direction he's facing. So I kinda lied. Direction does matter for the hammer and net, but it's done indepedently in an entirely separate part of the code. Furthermore, this means direction matters twice for slash and poke attacks.

As for why the sword can extend the hammer hitbox, that's just because a hitbox calculation is requested after the sword has placed its values, but before the offsets are reset again.

With just that much information, the calculations are super simple:

Where vi just indicates the variable came from our tables indexed by the X register, which we will call I to avoid confusion. The table is documented below, but keep reading afterwards.

SlBCash
Parameters
I x y w h I x y w h I x y w h I x y w h I x y w h
$00 0 0 15 15 $0D 0 0 0 0 $1A 1 1 6 6 $27 4 1 4 4 $34 −4 −2 10 8
$01 2 2 4 4 $0E 0 0 0 0 $1B 1 1 6 4 $28 2 2 4 4 $35 −4 0 14 8
$02 0 0 8 8 $0F 0 0 0 0 $1C 0 0 0 0 $29 2 2 4 4 $36 −10 −4 15 12
$03 0 2 8 2 $10 0 0 0 0 $1D 0 0 0 0 $2A 2 1 6 6 $37 0 1 4 4
$04 −8 4 8 12 $11 2 2 4 4 $1E 0 0 0 0 $2B 2 1 6 6 $38 2 2 4 4
$05 0 4 8 8 $12 4 0 16 8 $1F 0 0 0 0 $2C 0 0 0 0 $39 2 2 4 4
$06 2 4 12 12 $13 4 2 12 4 $20 0 0 0 0 $2D 0 0 0 0 $3A 0 1 6 6
$07 0 7 8 8 $14 0 −4 8 12 $21 0 0 8 8 $2E 0 0 0 0 $3B 0 1 6 6
$08 2 2 4 4 $15 0 −3 8 12 $22 0 0 8 8 $2F 0 0 0 0 $3C 0 0 0 0
$09 2 2 4 4 $16 −4 −8 12 12 $23 0 0 8 8 $30 0 0 0 0 $3D 0 0 0 0
$0A 1 1 6 6 $17 −4 0 11 4 $24 2 −2 10 8 $31 0 0 8 8 $3E 0 0 0 0
$0B 1 1 6 6 $18 −6 0 12 8 $25 2 0 14 8 $32 0 0 8 8 $3F 0 0 0 0
$0C 0 0 0 0 $19 2 2 4 4 $26 4 −4 15 12 $33 0 0 8 8 $40 0 0 0 0

Oddities

Interestingly, I didn't make any mention of how exactly a hitbox is cancelled. That's because, they kind of aren't. In the case where everything else fails the scratch space values are mostly left alone. The only one that isn't is the high byte of the x-coordinate, which will take on the value 0x80. This means the existing values will be used for the size and vertical position of the hitbox, but the horizontal position will be anywhere from −32513 to −32768 pixels away.

What about the offsets for the hammer? Most of the time, these extra offsets are 0x80. They are only set to proper values for a single frame. But, nothing actually prevents the hitbox from being created. Instead, it will just use that default value. Unfortunately, everything that requests an action hitbox also checks Oy beforehand, skipping the request and subsequent hitbox code if the value is exactly 0x80.

Before I go

And as one last thing: ya know that thing where you hit King Helma and then he clinks you and you see the clink at the bottom. What's that about?

At first, I thought it had to do with those offsets, since there's a routine for placing what's known as a repulse spark, and they're used in the calculation.

It turns out to be even dumber.

When you hit King Helma with the hammer while outmaneuvering him, the game uses a routine to calculate the velocity of Link's recoil. In doing so, it leaves some leftovers in scratch space. And for some got dang reason, right after doing that, those same leftovers are used for the coordinates of the repulse spark.

I think what they were going for is using the leftovers of the action hitbox routine for these coordinates, but, yeah…