Discuss Scratch

IndigantSitting14
Scratcher
24 posts

Need Help CODING a hitbox!

Hi! I'm trying to make a platformer but I don't know how to CODE a hitbox for collisions. Can you please help me? Thanks.
zxyxz
Scratcher
65 posts

Need Help CODING a hitbox!

Make a new costume in your player's sprite. Draw a Square for how big you want your character's hitbox to be.

Now, make sure when you're running the more complex parts of your script to switch the player costume to the hitbox one. Then, after collision has been detected and satisfied, switch it back.
NeonG4
Scratcher
1000+ posts

Need Help CODING a hitbox!

IndigantSitting14 wrote:

Hi! I'm trying to make a platformer but I don't know how to CODE a hitbox for collisions. Can you please help me? Thanks.
For coding a hitbox, are you trying to make a pen platformer? In this case, you would need to store the player x and y, and then you can create a hitbox by drawing a square that fits your requirements.

But for the code, for a pen player on pen grounds, you would need to figure out which x and y velocity is changing, and check that side of the hitbox.
like if your player is moving right, and there is a wall, you need to check the right hitbox wall. you can calculate if the hitbox line is over the wall line. This would then need to push the player out of the wall. Now just do this every tick. It sounds complex, so if you need help coding it up I'm here.

IndigantSitting14
Scratcher
24 posts

Need Help CODING a hitbox!

NeonG4 wrote:

IndigantSitting14 wrote:

Hi! I'm trying to make a platformer but I don't know how to CODE a hitbox for collisions. Can you please help me? Thanks.
For coding a hitbox, are you trying to make a pen platformer? In this case, you would need to store the player x and y, and then you can create a hitbox by drawing a square that fits your requirements.

But for the code, for a pen player on pen grounds, you would need to figure out which x and y velocity is changing, and check that side of the hitbox.
like if your player is moving right, and there is a wall, you need to check the right hitbox wall. you can calculate if the hitbox line is over the wall line. This would then need to push the player out of the wall. Now just do this every tick. It sounds complex, so if you need help coding it up I'm here.

I'm not making a pen platformer.
NeonG4
Scratcher
1000+ posts

Need Help CODING a hitbox!

IndigantSitting14 wrote:

NeonG4 wrote:

IndigantSitting14 wrote:

Hi! I'm trying to make a platformer but I don't know how to CODE a hitbox for collisions. Can you please help me? Thanks.
For coding a hitbox, are you trying to make a pen platformer? In this case, you would need to store the player x and y, and then you can create a hitbox by drawing a square that fits your requirements.

But for the code, for a pen player on pen grounds, you would need to figure out which x and y velocity is changing, and check that side of the hitbox.
like if your player is moving right, and there is a wall, you need to check the right hitbox wall. you can calculate if the hitbox line is over the wall line. This would then need to push the player out of the wall. Now just do this every tick. It sounds complex, so if you need help coding it up I'm here.

I'm not making a pen platformer.
Then why would you want to code a hitbox? What are you making?
09878901234321
Scratcher
500+ posts

Need Help CODING a hitbox!

Hello! What are you using the hitbox for?

Can you not use the
touchingsprite?
sensing block?
IndigantSitting14
Scratcher
24 posts

Need Help CODING a hitbox!

09878901234321 wrote:

Hello! What are you using the hitbox for?

Can you not use the
touchingsprite?
sensing block?
I'm using the hitbox for collisions so that the player can detect that they have hit a wall then the player should stop once he has touched a wall.
IndigantSitting14
Scratcher
24 posts

Need Help CODING a hitbox!

NeonG4 wrote:

IndigantSitting14 wrote:

NeonG4 wrote:

IndigantSitting14 wrote:

Hi! I'm trying to make a platformer but I don't know how to CODE a hitbox for collisions. Can you please help me? Thanks.
For coding a hitbox, are you trying to make a pen platformer? In this case, you would need to store the player x and y, and then you can create a hitbox by drawing a square that fits your requirements.

But for the code, for a pen player on pen grounds, you would need to figure out which x and y velocity is changing, and check that side of the hitbox.
like if your player is moving right, and there is a wall, you need to check the right hitbox wall. you can calculate if the hitbox line is over the wall line. This would then need to push the player out of the wall. Now just do this every tick. It sounds complex, so if you need help coding it up I'm here.

I'm not making a pen platformer.
Then why would you want to code a hitbox? What are you making?
I'm trying to make a simple platformer, but with good collisions. So I want to use a hitbox for that, but I don't know how to code it.
ztsereteli
Scratcher
91 posts

Need Help CODING a hitbox!

Just make a new sprite called “Player Hitbox” or something like that, and draw a square for how big you want the hitbox to be. Make the hitbox sprite always have a ghost effect of 100 (invisible but can still have collision), and make the sprite always go to the normal player sprite in a forever loop.

Every time collision is detected with the <if touching (Player)> block, replace the input with your new sprite. <if touching (Player Hitbox)>
NeonG4
Scratcher
1000+ posts

Need Help CODING a hitbox!

IndigantSitting14 wrote:

NeonG4 wrote:

IndigantSitting14 wrote:

NeonG4 wrote:

IndigantSitting14 wrote:

Hi! I'm trying to make a platformer but I don't know how to CODE a hitbox for collisions. Can you please help me? Thanks.
For coding a hitbox, are you trying to make a pen platformer? In this case, you would need to store the player x and y, and then you can create a hitbox by drawing a square that fits your requirements.

But for the code, for a pen player on pen grounds, you would need to figure out which x and y velocity is changing, and check that side of the hitbox.
like if your player is moving right, and there is a wall, you need to check the right hitbox wall. you can calculate if the hitbox line is over the wall line. This would then need to push the player out of the wall. Now just do this every tick. It sounds complex, so if you need help coding it up I'm here.

I'm not making a pen platformer.
Then why would you want to code a hitbox? What are you making?
I'm trying to make a simple platformer, but with good collisions. So I want to use a hitbox for that, but I don't know how to code it.
So, you want to code up a hitbox. When you said code, I thought you meant not using the costume editor.

I would watch a tutorial for platformers. Griffpatch has some. https://www.youtube.com/watch?v=D16hTnDGweo (episode 1)
PurpleSuit
Scratcher
500+ posts

Need Help CODING a hitbox!

just use a collison engine
lostindarkness
Scratcher
4 posts

Need Help CODING a hitbox!

me and my friend Toxiclandsgdash2-2 are racing to publish a platformer game frist and i cant figure hit boxes i need help pls
bsteichman
Scratcher
500+ posts

Need Help CODING a hitbox!

you could use a my block and a costume divided into 4 colors that don't appear in any other part of your project, if you want to know which edge of the player the hitbox touched

\ red /
\ /
blu\ / yellow
/ \
/ \
/ green \

then in your level sprite (floors n walls) you can do
whenIreceivesenseiftouchingcolor?thensetceilingto1elsesetceilingto0iftouchingcolor?thensetfloorto1elsesetfloorto0iftouchingcolor?thensetleftto1elsesetleftto0iftouchingcolor?thensetrightto1elsesetrightto0
and in your player sprite:
definehitboxswitchcostumetohitboxbroadcastsenseandwaitswitchcostumetoplayer
make sure to make the block “run without screen refresh” then it will try to complete all of this in one frame, so it won't show the hitbox to the user.

Last edited by bsteichman (Sept. 28, 2023 17:28:19)

lostindarkness
Scratcher
4 posts

Need Help CODING a hitbox!

it didnt work
lostindarkness
Scratcher
4 posts

Need Help CODING a hitbox!

wow
lostindarkness
Scratcher
4 posts

Need Help CODING a hitbox!

woahasignature
Death_theskull767
Scratcher
20 posts

Need Help CODING a hitbox!

I'm Trying to make a boss but I don't know how to do the hitbox to damage the player
:|
vdiu
Scratcher
100+ posts

Need Help CODING a hitbox!

Make a hitbox which is a square with a outline of 0.05 and no inside, and then use
whenclickedswitchcostumetohitboxcreatecloneofmyself
and then for the visible sprite
whenistartasacloneforeverswitchcostumetoplayergotoplayer
To get go to player go into another sprite and select go to player then drag it into your player sprite. If you want to animate use this instead
whenistartasacloneforeverbroadcastanimation loopgotoplayer
and for the actual animation
whenireceiveanimation loopifinsertwhatevercontrolsyou'reusingherethenswitchcostumetoplayer right
etc etc.

Powered by DjangoBB