Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do you "hit" the object precisely in Scratch?
- SoranoKiseki
-
3 posts
How do you "hit" the object precisely in Scratch?
So I've been playing with scratch in my AP CS class for about a week now, and I'm trying to make a dungeon game and now I'm working on the basic mechanics of game. And the attacking part has been a huge pain.
I have little artistic talent so now my basic idea is that I found some sprites online and an effect which looks sort of like a sword being swung, and I plan to stick with it, but the problem now is that it just WON'T work. The “touching” the attack effect swing command was a disaster because it works about 1% of the times and I have no idea why.
I tried to make a colored block and put in ghost mode then appears with the sprite, and the hit gets detected by a color sensor, however it still won't work.
Now I came up with a super long script which has the basic idea of:
1.Change a “Hit Right” Variable to 1 and then back to 0 when I hit right.
2.If “Hit Right” is 1, a clone would check the difference between its of x and y coordination and the hidden attack sprite.
3.If the x y differences are within a certain range, then it “receives the attack” and reacts.
However the problem is, the way I make the game makes the distance difference huge, and I guess that is why the attack won't work for most of the times. But I changed the x y range to allow a very large difference. It still doesn't work.
And even if it does, it is still a incredibly redundant method.
I really need some good suggestions, thank you very much
Here's the link of the project, I shared it for help although it is undone.
https://scratch.mit.edu/projects/125315412/
I have little artistic talent so now my basic idea is that I found some sprites online and an effect which looks sort of like a sword being swung, and I plan to stick with it, but the problem now is that it just WON'T work. The “touching” the attack effect swing command was a disaster because it works about 1% of the times and I have no idea why.
I tried to make a colored block and put in ghost mode then appears with the sprite, and the hit gets detected by a color sensor, however it still won't work.
Now I came up with a super long script which has the basic idea of:
1.Change a “Hit Right” Variable to 1 and then back to 0 when I hit right.
2.If “Hit Right” is 1, a clone would check the difference between its of x and y coordination and the hidden attack sprite.
3.If the x y differences are within a certain range, then it “receives the attack” and reacts.
However the problem is, the way I make the game makes the distance difference huge, and I guess that is why the attack won't work for most of the times. But I changed the x y range to allow a very large difference. It still doesn't work.
And even if it does, it is still a incredibly redundant method.
I really need some good suggestions, thank you very much

Here's the link of the project, I shared it for help although it is undone.
https://scratch.mit.edu/projects/125315412/
- Cuffrox
-
44 posts
How do you "hit" the object precisely in Scratch?
Little confused of what you're after?
- SoranoKiseki
-
3 posts
How do you "hit" the object precisely in Scratch?
Basically I just want to create a hitting detection mechanism for my game in which visually seeing the sprite “touching” the enemy would “hit” the enemy. Instead of whatever way scratch's default is Little confused of what you're after?
- eh6239qr
-
100+ posts
How do you "hit" the object precisely in Scratch?
You may want to try a combination of the collision detection and color detection.
- amylaser
-
500+ posts
How do you "hit" the object precisely in Scratch?
I think the simplest solution would just be to put the sword in a separate sprite, and “summon” it next to the player whenever the player is in attack mode. All you have to do is make sure that the sword sprite is forever pointing in the same direction and occupying the same position as the player sprite.
Anyway, I made a remix of your game that should hopefully give you some pointers. Here's the link to the remix: https://scratch.mit.edu/projects/125775819/
(Not sure if you knew this, but local variables are unique to clones.)
For the sake of my sanity I deleted a lot of the extraneous sprites and scripts, and I made it so that three snowmen will spawn on the screen in random locations, each starting with 50 health and a random Gold Drop (so that you will get gold coins once you defeat it). These snowmen will move towards the player once every second (I did that to mimic some games I've played before, but you can get rid of the 1-second delay if you want). If the snowmen are hit by an attack, they'll also lose 20 health points and flash briefly. I also tweaked the Player movement scripts a bit and added the attack mechanism you initially asked for.
Hope it helps
Anyway, I made a remix of your game that should hopefully give you some pointers. Here's the link to the remix: https://scratch.mit.edu/projects/125775819/
(Not sure if you knew this, but local variables are unique to clones.)
For the sake of my sanity I deleted a lot of the extraneous sprites and scripts, and I made it so that three snowmen will spawn on the screen in random locations, each starting with 50 health and a random Gold Drop (so that you will get gold coins once you defeat it). These snowmen will move towards the player once every second (I did that to mimic some games I've played before, but you can get rid of the 1-second delay if you want). If the snowmen are hit by an attack, they'll also lose 20 health points and flash briefly. I also tweaked the Player movement scripts a bit and added the attack mechanism you initially asked for.
Hope it helps

- SoranoKiseki
-
3 posts
How do you "hit" the object precisely in Scratch?
Thank you so much! Although I don't understand because in the beginning I used pretty much the same method as clone sword and point, but mine barely hits the mark. And I have no idea why, the biggest difference I can see is that you set it to “point to the player's direction” whereas I did four directions (90 -90 0 and 180) I think the simplest solution would just be to put the sword in a separate sprite, and “summon” it next to the player whenever the player is in attack mode. All you have to do is make sure that the sword sprite is forever pointing in the same direction and occupying the same position as the player sprite.
Anyway, I made a remix of your game that should hopefully give you some pointers. Here's the link to the remix: https://scratch.mit.edu/projects/125775819/
(Not sure if you knew this, but local variables are unique to clones.)
For the sake of my sanity I deleted a lot of the extraneous sprites and scripts, and I made it so that three snowmen will spawn on the screen in random locations, each starting with 50 health and a random Gold Drop (so that you will get gold coins once you defeat it). These snowmen will move towards the player once every second (I did that to mimic some games I've played before, but you can get rid of the 1-second delay if you want). If the snowmen are hit by an attack, they'll also lose 20 health points and flash briefly. I also tweaked the Player movement scripts a bit and added the attack mechanism you initially asked for.
Hope it helps
About the snowman health, I did know about local variable and I made an entire list to track the health, now I realize that it is unnecessary because other sprites don't need to access its health.
Also your variable looks much more advanced and simple than mine, mine looks rural compared to yours, thank you so much

Last edited by SoranoKiseki (Oct. 17, 2016 17:43:53)
- th_ahsu
-
4 posts
How do you "hit" the object precisely in Scratch?
move (2) steps
move (-2) steps
move (10) steps
move (-10) steps
if <key space> then
switch costume to [ 2
- deck26
-
1000+ posts
How do you "hit" the object precisely in Scratch?
:I
Please doin't spam or necropost.
Last edited by deck26 (June 3, 2020 11:07:08)
- cartermgoogly
-
1 post
How do you "hit" the object precisely in Scratch?
You may want to try a combination of the collision detection and color detection.
- Wyan100
-
1000+ posts
How do you "hit" the object precisely in Scratch?
Please don't necropost
- KahnSeri
-
1 post
How do you "hit" the object precisely in Scratch?
So I've been playing with scratch in my AP CS class for about a week now, and I'm trying to make a dungeon game and now I'm working on the basic mechanics of game. And the attacking part has been a huge pain.
I have little artistic talent so now my basic idea is that I found some sprites online and an effect which looks sort of like a sword being swung, and I plan to stick with it, but the problem now is that it just WON'T work. The “touching” the attack effect swing command was a disaster because it works about 1% of the times and I have no idea why.
I tried to make a colored block and put in ghost mode then appears with the sprite, and the hit gets detected by a color sensor, however it still won't work.
Now I came up with a super long script which has the basic idea of:
1.Change a “Hit Right” Variable to 1 and then back to 0 when I hit right.
2.If “Hit Right” is 1, a clone would check the difference between its of x and y coordination and the hidden attack sprite.
3.If the x y differences are within a certain range, then it “receives the attack” and reacts.
However the problem is, the way I make the game makes the distance difference huge, and I guess that is why the attack won't work for most of the times. But I changed the x y range to allow a very large difference. It still doesn't work.
And even if it does, it is still a incredibly redundant method.
I really need some good suggestions, thank you very much
Here's the link of the project, I shared it for help although it is undone.
I have little artistic talent so now my basic idea is that I found some sprites online and an effect which looks sort of like a sword being swung, and I plan to stick with it, but the problem now is that it just WON'T work. The “touching” the attack effect swing command was a disaster because it works about 1% of the times and I have no idea why.
I tried to make a colored block and put in ghost mode then appears with the sprite, and the hit gets detected by a color sensor, however it still won't work.
Now I came up with a super long script which has the basic idea of:
1.Change a “Hit Right” Variable to 1 and then back to 0 when I hit right.
2.If “Hit Right” is 1, a clone would check the difference between its of x and y coordination and the hidden attack sprite.
3.If the x y differences are within a certain range, then it “receives the attack” and reacts.
However the problem is, the way I make the game makes the distance difference huge, and I guess that is why the attack won't work for most of the times. But I changed the x y range to allow a very large difference. It still doesn't work.
And even if it does, it is still a incredibly redundant method.
I really need some good suggestions, thank you very much
Here's the link of the project, I shared it for help although it is undone.
- hihi600
-
4 posts
How do you "hit" the object precisely in Scratch?
I meant how do you do collision detection.
- th_ahsu
-
4 posts
How do you "hit" the object precisely in Scratch?
u make hit boxes for the things u want to have collision den u check to see if dare touchin' and dats about it also for hitbox follow code: I meant how do you do collision detection.
dats for the guy dude thing for hit box is:
also the orange vars are sopust to be the xpos of ___ and ypos of ____ da light blue blocks
hope dis helps
Last edited by th_ahsu (April 1, 2021 20:34:00)
- Discussion Forums
- » Help with Scripts
-
» How do you "hit" the object precisely in Scratch?