How do I make a Hit box?

id: 750841

category: Help with Scripts

posts: 5

Adamm386 Adamm386 loading
How do I make a proper hit box?
It's in the name, you make a box that detects if things hit it. In a nutshell, you would put your normal movement controls in the hitbox (like WASD). Then it would check if it was touching anything, like walls or enemies. If you want to make graphics for the character, you can set the ghost effect of the hitbox to 100 and make a new sprite follow the hitbox.
Adamm386 Adamm386 loading
Can you please show me, like in commands?

Adamm386 wrote:

Can you please show me, like in commands?
Sure.

Here we have Scratch Cat and its hitbox, which is in red.


Here's the code that I use to move the hitbox around:
when green flag clicked
forever
if <key [w v] pressed?> then
change y by (10)
end
if <key [s v] pressed?> then
change y by (-10)
end
if <key [d v] pressed?> then
change x by (10)
end
if <key [a v] pressed?> then
change x by (-10)
end
end

I always want Scratch Cat to follow my hitbox because that's the costume I want to show the player:
when green flag clicked
forever
go to [hitbox v]
end

Usually, we don't want to see the hitbox, so we can set the ghost effect to 100. That makes sure the hitbox can still interact with other sprites, but you can't see it:
set [ghost v] effect to (100)