0:01 / 0:30
Playback speed

Hurtbox

Watch the green outline before the swing. Is the target vulnerable all the way to the edge of its artwork?

#Collision

The invisible shape on a character that can be hit.

The green boxes are hurtboxes. They’re often a little smaller than the sprite so near-misses go the player’s way. A hit happens when someone’s hitbox overlaps someone else’s hurtbox.

Code

src/demos/hitbox.goose
namespace hitbox_lesson;
import stage;
import std;
import math;

export "hitbox" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    artwork("hall", 0, 0, W, 112);
    let t = time % 1.5;
    let attack = t > 0.55 && t < 0.85;
    let lunge = if attack { 6 } else { 0 };
    let hit_x = 56 + lunge;
    let struck = attack && hit_x < 132 && hit_x + 50 > 102;
    ground(70);
    actor(37 + lunge, 82, if attack { REACH } else { STAND }, 3, "base", "knight");
    actor(117 + (if struck { 3 } else { 0 }), 82, if struck { LAND } else { STAND }, 3, if struck { "white" } else { "rose" }, "knight", true);
    if attack {
        quad(58 + lunge, 50, 100 + lunge, 60, 58 + lunge, 72, 72 + lunge, 60, WHITE);
        opacity(0.4);
        rect(hit_x, 54, 50, 14, RED);
        opacity(1);
        box(hit_x, 54, 50, 14, RED);
    }
    box(22 + lunge, 46, 30, 34, MOSS);
    box(102 + (if struck { 3 } else { 0 }), 46, 30, 34, MOSS);
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.