Discuss Scratch

iron_Dense
New Scratcher
11 posts

How can I make invisible hitboxes?

Title basically says it all.
I'm trying to make a SHMUP game so i put a hitbox at the very top to make the bullets disappear if they miss enemies. But after a while of trying and messing with the ghosting block I still can't make it disappear without it stopping to work.
Anonymous1212144
Scratcher
100+ posts

How can I make invisible hitboxes?

Use this:

set [ghost v] effect to [100]
-Snipet-
Scratcher
500+ posts

How can I make invisible hitboxes?

Griffpatch’s platform tutorial is a good example of this.
iron_Dense
New Scratcher
11 posts

How can I make invisible hitboxes?

I've tried the ghost effect block but when i use it,the hitbox stops working.
I've heard that you have to actually set it at 99 isntead of 100,but that doesn't work either
StrangeMagic32
Scratcher
1000+ posts

How can I make invisible hitboxes?

forever
switch costume to [hitbox v]
code::grey
switch costume to [costume v]
end

or do what @-Snipet- said
Anonymous1212144
Scratcher
100+ posts

How can I make invisible hitboxes?

iron_Dense wrote:

I've tried the ghost effect block but when i use it,the hitbox stops working.
I've heard that you have to actually set it at 99 isntead of 100,but that doesn't work either
Are you sure that the sprite is actually showing?
iron_Dense
New Scratcher
11 posts

How can I make invisible hitboxes?

Anonymous1212144 wrote:

iron_Dense wrote:

I've tried the ghost effect block but when i use it,the hitbox stops working.
I've heard that you have to actually set it at 99 isntead of 100,but that doesn't work either
Are you sure that the sprite is actually showing?

Yeah,it's showing and working but when i apply the ghosting effect it stops working
user_Matteo
Scratcher
43 posts

How can I make invisible hitboxes?

Maybe a script like this will work:
when green flag clicked
forever
code
if <(y position) > [180]> then
code to delete bullet
end
if <(y position) < [-180]> then
code to delete bullet
end
if <(x position) > [240]> then
code to delete bullet
end
if <(x position) < [-240]> then
code to delete bullet
end

in theory, when the bullets go out the screen they will be deleted
success whith your project!
iron_Dense
New Scratcher
11 posts

How can I make invisible hitboxes?

user_Matteo wrote:

Maybe a script like this will work:
when green flag clicked
forever
code
if <(y position) > [180]> then
code to delete bullet
end
if <(y position) < [-180]> then
code to delete bullet
end
if <(x position) > [240]> then
code to delete bullet
end
if <(x position) < [-240]> then
code to delete bullet
end

in theory, when the bullets go out the screen they will be deleted
success whith your project!


Yeah a simple if y > 180 does work perfectly…but i was more of asking to know how hitboxes work in general for later use.
user_Matteo
Scratcher
43 posts

How can I make invisible hitboxes?

oh… ok!
iron_Dense
New Scratcher
11 posts

How can I make invisible hitboxes?

StrangeMagic32 wrote:

forever
switch costume to [hitbox v]
code::grey
switch costume to [costume v]
end

or do what @-Snipet- said


I don't get that. When the costume is set to the hitboxes it would be active but also visible. And when it switches to costume,the hitbox would disappear but also become unusable,right?
Tallented-Code-bot
Scratcher
100+ posts

How can I make invisible hitboxes?

iron_Dense wrote:

StrangeMagic32 wrote:

forever
switch costume to [hitbox v]
code::grey
switch costume to [costume v]
end

or do what @-Snipet- said


I don't get that. When the costume is set to the hitboxes it would be active but also visible. And when it switches to costume,the hitbox would disappear but also become unusable,right?
the reson that you can not see the hitbox is because it is in a forever loop and repeating so fast that all you see is the costume.
You would put all the code that uses the hitbox in between the switch costume to hitbox block and the switch costume to costume block.
then you would see the costume, but the program sees the hitbox and uses it instead of the costume.
iron_Dense
New Scratcher
11 posts

How can I make invisible hitboxes?

Tallented-Code-bot wrote:

iron_Dense wrote:

StrangeMagic32 wrote:

forever
switch costume to [hitbox v]
code::grey
switch costume to [costume v]
end

or do what @-Snipet- said


I don't get that. When the costume is set to the hitboxes it would be active but also visible. And when it switches to costume,the hitbox would disappear but also become unusable,right?
the reson that you can not see the hitbox is because it is in a forever loop and repeating so fast that all you see is the costume.
You would put all the code that uses the hitbox in between the switch costume to hitbox block and the switch costume to costume block.
then you would see the costume, but the program sees the hitbox and uses it instead of the costume.

Oh…I kind of get it now. But the problem is that i am already flickering between costumes.
See i don't want to see just a static image floating around. So for my rocketships i have 2 costumes,which have slightly different looking flames that come out of them.
I use a forever loop to switch between the two every 0.2 seconds.

Do you know of any solutions to this? How can i make an invisible hitbox now?
imfh
Scratcher
1000+ posts

How can I make invisible hitboxes?

Try using it in a no refresh block. A custom block with no refresh enabled will run without updating the screen. This means it will switch costume but not be seen. This is how it is done in the Platformer Tutorial mentioned above twice.

define No Refresh Check Collision
switch costume to [hitbox v]
Check collision here :: grey
switch costume to [normal v]

It is probably a lot more efficient to use x position for this case however since touching has a lot of calculations it has to go through. Even if 180 is exactly right, you should be able to adjust it to get something that works.
StrangeMagic32
Scratcher
1000+ posts

How can I make invisible hitboxes?

iron_Dense wrote:

Tallented-Code-bot wrote:

iron_Dense wrote:

StrangeMagic32 wrote:

forever
switch costume to [hitbox v]
code::grey
switch costume to [costume v]
end

or do what @-Snipet- said


I don't get that. When the costume is set to the hitboxes it would be active but also visible. And when it switches to costume,the hitbox would disappear but also become unusable,right?
the reson that you can not see the hitbox is because it is in a forever loop and repeating so fast that all you see is the costume.
You would put all the code that uses the hitbox in between the switch costume to hitbox block and the switch costume to costume block.
then you would see the costume, but the program sees the hitbox and uses it instead of the costume.

Oh…I kind of get it now. But the problem is that i am already flickering between costumes.
See i don't want to see just a static image floating around. So for my rocketships i have 2 costumes,which have slightly different looking flames that come out of them.
I use a forever loop to switch between the two every 0.2 seconds.

Do you know of any solutions to this? How can i make an invisible hitbox now?
I'll make a project to help show you how
StrangeMagic32
Scratcher
1000+ posts

How can I make invisible hitboxes?

StrangeMagic32 wrote:

iron_Dense wrote:

Oh…I kind of get it now. But the problem is that i am already flickering between costumes.
See i don't want to see just a static image floating around. So for my rocketships i have 2 costumes,which have slightly different looking flames that come out of them.
I use a forever loop to switch between the two every 0.2 seconds.

Do you know of any solutions to this? How can i make an invisible hitbox now?
I'll make a project to help show you how
done
https://scratch.mit.edu/projects/291538518/
iron_Dense
New Scratcher
11 posts

How can I make invisible hitboxes?

StrangeMagic32 wrote:

StrangeMagic32 wrote:

iron_Dense wrote:

Oh…I kind of get it now. But the problem is that i am already flickering between costumes.
See i don't want to see just a static image floating around. So for my rocketships i have 2 costumes,which have slightly different looking flames that come out of them.
I use a forever loop to switch between the two every 0.2 seconds.

Do you know of any solutions to this? How can i make an invisible hitbox now?
I'll make a project to help show you how
done
https://scratch.mit.edu/projects/291538518/

Yeah,too complex for a simpleton like me.

I tried doing random things myself and am actually kind of able to make something.
The animations work fine and the hitbox is invisible. But when the hitbox code is activated (for example: If color x is touching color y say “I'm hit!” for 2 seconds) then for 2 seconds,the hitbox is shown.
iron_Dense
New Scratcher
11 posts

How can I make invisible hitboxes?

Sigh,forget it guys.
I'm just gonna use the touch command…I'd much rather be using a normal hitbox but eh whatever
StrangeMagic32
Scratcher
1000+ posts

How can I make invisible hitboxes?

iron_Dense wrote:

StrangeMagic32 wrote:

StrangeMagic32 wrote:

iron_Dense wrote:

Oh…I kind of get it now. But the problem is that i am already flickering between costumes.
See i don't want to see just a static image floating around. So for my rocketships i have 2 costumes,which have slightly different looking flames that come out of them.
I use a forever loop to switch between the two every 0.2 seconds.

Do you know of any solutions to this? How can i make an invisible hitbox now?
I'll make a project to help show you how
done
https://scratch.mit.edu/projects/291538518/

Yeah,too complex for a simpleton like me.

I tried doing random things myself and am actually kind of able to make something.
The animations work fine and the hitbox is invisible. But when the hitbox code is activated (for example: If color x is touching color y say “I'm hit!” for 2 seconds) then for 2 seconds,the hitbox is shown.
broadcast [hit v]
when I receive [hit v]
say [I'm hit] for (2) secs
imfh
Scratcher
1000+ posts

How can I make invisible hitboxes?

It doesn't have to be complicated. Unmodified, something like this will work:

define Check collision
set [costume v] to (costume #)
switch costume to [hitbox v]
if <touching [something v] ?> then
set [hit v] to [1]
else
set [hit v] to [0]
end
switch costume to (costume)

The problem you are having is that you are putting a wait block between the switch to hitbox and switch to normal costume. If you do that, Scratch will wait a bit before switching back. Without a wait, it should switch back quickly enough that it doesn't show it on the screen.

It might help if you share the project so we can see it. Hitbox code is often better when customized for the project. It's possible we will be able to find a better way for what you are doing.

Powered by DjangoBB