Discuss Scratch

Frioc
Scratcher
27 posts

How would you make a hitbox have attack points like in smash bros?

I wanted to make a smash bros type game, but idk to make the enemy sense when the other player uses a move. I mean, could I just make another sprite called “hurtbox” and have that go to the hitbox?

I looked at @Hobson-TV's famous Super Scratch Bros game and it was waaay to complex for me to understand, but I think it uses pen to draw the attacks hitbox

For reffernce I mean these
ThreeLived
Scratcher
100+ posts

How would you make a hitbox have attack points like in smash bros?

From your source provided, it seems that its using a bunch of circles. I hope you already know about the Pythagorean theorem, because its really important here. For context, its often used in the distance formula for a circle.

If you want to make a scratch game using the system in your source, you could add a bunch of positions to a list (and include their size) and check if a given point is within it.

a simplified version might be creating a circle around the attack's area and seeing if it collides with the player's circle (just subtract the radius of the player's circle to get its distance to the attack's circle)
Frioc
Scratcher
27 posts

How would you make a hitbox have attack points like in smash bros?

I see how that could work, but what if the other players hitbox is a square not a circle? Also is it better to calculate the players hitboxes with code or with another sprite
ThreeLived
Scratcher
100+ posts

How would you make a hitbox have attack points like in smash bros?

Using another sprite works… until it doesnt. If a sprite is offscreen or you plan to allow scrolling, sprites become awful.

As for squares, they are super simple.
They are literally just the x difference and y difference
it looks like this:

set [distance v] to ( [abs v] (((attack x) - (player x)) + ((attack y) - (player y)))::operations)::operations //absolute value may not be needed. its just in case

Last edited by ThreeLived (Yesterday 22:26:23)

Frioc
Scratcher
27 posts

How would you make a hitbox have attack points like in smash bros?

I'm probably wrong but Isn't that only the distance to one coordinate though? Like one pixel?
ThreeLived
Scratcher
100+ posts

How would you make a hitbox have attack points like in smash bros?

it is. you just have to check if its less than the size of the hitbox

if <(distance_) < [hitbox size (you decide what it is)]> then
do something depending on what you want to do ::motion
end
Spider-forge
Scratcher
13 posts

How would you make a hitbox have attack points like in smash bros?

You could maybe use a filled in box sprite with 100 percent ghost effect, then change a global variable of whether a specific attack is playing or not, then if it is playing and both people are in the hitbox, deal damage. Maybe this is too simple though?
Pseudocode:
set [Ghost] effect to (100)
forever
if <<(attack_playing) = [1]> and <touching [ sprite v] ?>> then
deal damage
end
end
ThreeLived
Scratcher
100+ posts

How would you make a hitbox have attack points like in smash bros?

Spider-forge wrote:

You could maybe use a filled in box sprite with 100 percent ghost effect, then change a global variable of whether a specific attack is playing or not, then if it is playing and both people are in the hitbox, deal damage. Maybe this is too simple though?
Pseudocode:
set [Ghost] effect to (100)
forever
if <<(attack_playing) = [1]> and <touching [ sprite v] ?>> then
deal damage
end
end
I think this would work, but i tend to find sprite to sprite collisions unreliable. It only really becomes super relevant if you use camera controls (especially zoom, then it gets really bad), so it could work for OP's project depending on how its structured
Frioc
Scratcher
27 posts

How would you make a hitbox have attack points like in smash bros?

Nah I tried using a camera, did not go well, but I am using the system he just described for detections but I'm experimenting with the math one because it seems much more reliable
ThreeLived
Scratcher
100+ posts

How would you make a hitbox have attack points like in smash bros?

Frioc wrote:

Nah I tried using a camera, did not go well, but I am using the system he just described for detections but I'm experimenting with the math one because it seems much more reliable
are you having trouble making a camera ? did you want help making one, or are you just talking about sprite collisions?
Frioc
Scratcher
27 posts

How would you make a hitbox have attack points like in smash bros?

Ok squares and circles are simple enough but how would you calculate a shape like a rectangle where the sides aren't even? Also the script you gave me to calculate a square calculated a circle

Last edited by Frioc (Today 14:44:20)

awesome-llama
Scratcher
1000+ posts

How would you make a hitbox have attack points like in smash bros?

ThreeLived wrote:

As for squares, they are super simple.
They are literally just the x difference and y difference
it looks like this:

set [distance v] to ([abs v] of (((attack x) - (player x)) + ((attack y) - (player y))))//absolute value may not be needed. its just in case
That doesn't make a useful shape.
If you found the absolute value of the x and y axes separately you would have a diamond shape (see taxicab geometry).

For an axis-aligned rectangle or square using a similar method, you would separate the distance checks:

<<([abs v] of ((attack x) - (player x))) < (dist)> and <([abs v] of ((attack y) - (player y))) < (dist)>>

Last edited by awesome-llama (Today 14:42:38)

ThreeLived
Scratcher
100+ posts

How would you make a hitbox have attack points like in smash bros?

ignore this use @awesome-llama 's approach

^^^ speaking of, i wonder if thats why i could never get cubes to work in raymarching lol. may try to make another one in the future







if <(ΔX) < (horizontal hitbox side)> then
if <(ΔY) < (vertical hitbox side)> then
[you collided with something] ::#000000
end
end
ΔX – x difference
ΔY – y difference

just make sure they are both in absolute value because i believe it matters here. (abs block)

Last edited by ThreeLived (Today 14:46:24)

Frioc
Scratcher
27 posts

How would you make a hitbox have attack points like in smash bros?

awesome-llama wrote:

That doesn't make a useful shape.
If you found the absolute value of the x and y axes separately you would have a diamond shape (see taxicab geometry).

For an axis-aligned rectangle or square using a similar method, you would separate the distance checks:

<<([abs v] of ((attack x) - (player x))) < (dist)> and <([abs v] of ((attack y) - (player y))) < (dist)>>

In this case what is the new distance formula?

Last edited by Frioc (Today 14:59:30)

ThreeLived
Scratcher
100+ posts

How would you make a hitbox have attack points like in smash bros?

Frioc wrote:

In this case what is the new distance formula?

probably what awesome-llama said:

<<([abs v] of ((attack x) - (player x))) < (dist)> and <([abs v] of ((attack y) - (player y))) < (dist)>>

if you mean what is the dist variable, i think thats your hitbox size

<<([abs v] of ((attack x) - (player x))) < (hitbox width)> and <([abs v] of ((attack y) - (player y))) < (hitbox height)>>

i think that should work ? i havent tested it out yet.
Frioc
Scratcher
27 posts

How would you make a hitbox have attack points like in smash bros?

OOOOOOHHHHH Thats poggers thanks
Frioc
Scratcher
27 posts

How would you make a hitbox have attack points like in smash bros?

Is there any way to visualize the hitbox with pen to make it easier to see? or would that require lots of list work
Frioc
Scratcher
27 posts

How would you make a hitbox have attack points like in smash bros?

If I want that hitbox and the ground to collide instead of the sprite detecting if the costume is touching, would the ground need a hitbox as well?
ThreeLived
Scratcher
100+ posts

How would you make a hitbox have attack points like in smash bros?

Frioc wrote:

Is there any way to visualize the hitbox with pen to make it easier to see? or would that require lots of list work
I would just set an x and y position to the mouse's position and show a variable saying something like (hello) if collision is detected.

this is just a really lazy way to do it, but it should at least be able to check if theres collision. You could come up with a WAY better solution but that would take longer. i would just use this until you can confirm it works and then create a better system for it

when green flag clicked
forever
set [x v] to ((mouse x) + (Camera X)) //if you dont have camera controls, just use mouse X or mouse Y for these
set [y v] to ((mouse y) + (Camera Y))

get if collision detected
if <collision detected> then
say [hello]
else
say []
end
end
ThreeLived
Scratcher
100+ posts

How would you make a hitbox have attack points like in smash bros?

Frioc wrote:

If I want that hitbox and the ground to collide instead of the sprite detecting if the costume is touching, would the ground need a hitbox as well?
yes, and if you plan to use floating platforms dont forget to give each one a hitbox

Powered by DjangoBB