Discuss Scratch

stephgeorge
Scratcher
48 posts

Can someone help me with a hit-box script for my game?

because I don't want my characters falling through everything, so I need a hit-box script for certain objects.
I need it because I am making a Platformer game and I don't want the character to phase through everything.
I'm using it for a scrolling platformer btw if you were wondering.

Last edited by stephgeorge (May 18, 2021 13:02:35)

The_Imaginarium
Scratcher
1000+ posts

Can someone help me with a hit-box script for my game?

You need to be more specific.
SuperDragonStudios
Scratcher
500+ posts

Can someone help me with a hit-box script for my game?

when green flag clicked
set [frame v] to (number of first run frame)
forever
switch costume to [hitbox v]
movement scripts
collision scripts
switch costume to (frame)
if <(frame) > (however many run frames you have)> then
set [frame v] to (number of your sprite's first run frame)

This is a simple little script that I hope helps you. You make a hitbox costume for your sprite and make sure your run frames are all in order, and not mixed with the rest of the costumes (make sure the hitbox costume is not in the middle of your run frames. Put it before or after the run frames).

The way the script works is as follows: The costume is switched to the hitbox, then the movement and collisions scripts take place (so it is detecting the ground as the hitbox costume), then it switches back to your run frame. It does this so fast that you can't even tell that it switched to the hitbox.

I'm not the best with explaining things, but I hope this helps.

Hello! I'm a 9th grader who used to be very active on Scratch.

I'm on a mission to get to 1,000 posts. I'm 49% through the journey (as of October 4th, 2023).
SuperDragonStudios
Scratcher
500+ posts

Can someone help me with a hit-box script for my game?

If you need a collision script to stop your character falling through the ground, use this script:

Make a custom block called “Touch Ground” and make sure to click “run without screen refresh”

here is what you put in the “define Touch Ground” block:
repeat until <not <touching [ground v] ?>
set [Y Velocity v] to (0)
change y by (1)
end

That is a basic floor collision script. If the scroller involves jumping, then you need to very slightly modify the script.

Again, I hope this helps.

Hello! I'm a 9th grader who used to be very active on Scratch.

I'm on a mission to get to 1,000 posts. I'm 49% through the journey (as of October 4th, 2023).
mayvenray
Scratcher
30 posts

Can someone help me with a hit-box script for my game?

when green flag clicked
forever
switch costume to [ hitbox]
if <key [ your code] pressed?> then

end
switch costume to [ your player]
end

I hope it helps

Powered by DjangoBB