Discuss Scratch

SoranoKiseki
Scratcher
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/
Cuffrox
Scratcher
44 posts

How do you "hit" the object precisely in Scratch?

Little confused of what you're after?
SoranoKiseki
Scratcher
3 posts

How do you "hit" the object precisely in Scratch?

Cuffrox wrote:

Little confused of what you're after?
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
eh6239qr
Scratcher
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
Scratcher
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
SoranoKiseki
Scratcher
3 posts

How do you "hit" the object precisely in Scratch?

amylaser wrote:

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
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)

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
Scratcher
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
wait0.1secsswitchcostumeto 1]
Ginge_A1234
Scratcher
1 post

How do you "hit" the object precisely in Scratch?

:I
deck26
Scratcher
1000+ posts

How do you "hit" the object precisely in Scratch?

th_ahsu wrote:

move2stepsmove-2stepsmove10stepsmove-10stepsifkeyspacethenswitchcostumeto 2wait0.1secsswitchcostumeto 1


Ginge_A1234 wrote:

:I

Please doin't spam or necropost.

Last edited by deck26 (June 3, 2020 11:07:08)

cartermgoogly
Scratcher
1 post

How do you "hit" the object precisely in Scratch?

eh6239qr wrote:

You may want to try a combination of the collision detection and color detection.

Matthewkoko189
New Scratcher
1 post

How do you "hit" the object precisely in Scratch?

Wyan100
Scratcher
1000+ posts

How do you "hit" the object precisely in Scratch?

Matthewkoko189 wrote:


Please don't necropost
KahnSeri
New Scratcher
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.
SparshG
Scratcher
500+ posts

How do you "hit" the object precisely in Scratch?

Make your own topic here instead of posting on 4 year old one…
hihi600
Scratcher
4 posts

How do you "hit" the object precisely in Scratch?

How?
hihi600
Scratcher
4 posts

How do you "hit" the object precisely in Scratch?

I meant how do you do collision detection.
th_ahsu
Scratcher
4 posts

How do you "hit" the object precisely in Scratch?

hihi600 wrote:

I meant how do you do collision detection.
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:
whenclickedforeverbroadcastsomin'

dats for the guy dude thing for hit box is:
whenIreceivegotox:xposofsomin'y:yposofsomin'

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)

Powered by DjangoBB