0
\$\begingroup\$

I'd like to replicate this game's mechanic of the player smashing walls with a precise timing to a background rhythm.

How should I check when each wall should be broken? Does the player animation use a hitbox, or does it use timing to detect if the smashing animation should play?

\$\endgroup\$
1
\$\begingroup\$

You need only simple collision detection for something like this: You could just compare the X-coordinate of the nearest wall with that of the player when the player throws a punch.

Something along the lines of

if (wall.x - player.x <= 50 && wall.x - player.x > 0) {
    // The wall is in a good position!
} else {
    // The wall is out of reach!
}

I used 50 as the maximum target distance here. Change it to fit the needs of your game.

If you would want this to be a part of an animation, just run this check in select frames of your animation, where the player's punch would be valid.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.