Discuss Scratch

invalidaccess
Scratcher
100+ posts

NEED HELP FOR SHOOTER

im making a 2D shooter game. im done with shooting scripts but i dont know how to check if the bullet goes off the screen and touches the enemy

Last edited by invalidaccess (March 29, 2024 19:47:45)

invalidaccess
Scratcher
100+ posts

NEED HELP FOR SHOOTER

SpyCoderX
Scratcher
500+ posts

NEED HELP FOR SHOOTER

invalidaccess wrote:

im making a 2D shooter game. im done with shooting scripts but i dont know how to check if the bullet goes off the screen and touches the enemy
Use these blocks to detect if your are touching the edge or an enemy:
<touching [Enemy v] ?>
<touching [edge v] ?>
Note: Add a “wait 0 seconds” block before deleting the bullet or the enemy clones might not detect the bullet hitting them (same for the enemy clones).

New game! (link)
Have a good day/night!


\(-_-) ::#00AAAA //This is crypto. He protects my signature from the evil kumquats!
Programming is a very powerful skill. As are critical thinking and hard work.
- SpyCoderX


invalidaccess
Scratcher
100+ posts

NEED HELP FOR SHOOTER

what if the enemy isnt in the scene . imean it goes off the screen and you cant see it so this not gonna work (i tryed so many times)
invalidaccess
Scratcher
100+ posts

NEED HELP FOR SHOOTER

SpyCoderX wrote:

invalidaccess wrote:

im making a 2D shooter game. im done with shooting scripts but i dont know how to check if the bullet goes off the screen and touches the enemy
Use these blocks to detect if your are touching the edge or an enemy:
<touching [Enemy v] ?>
<touching [edge v] ?>
Note: Add a “wait 0 seconds” block before deleting the bullet or the enemy clones might not detect the bullet hitting them (same for the enemy clones).
NEED HELP FOR SHOOTER
what if the enemy isnt in the scene . imean it goes off the screen and you cant see it so this not gonna work (i tryed so many times)
Malicondi
Scratcher
1000+ posts

NEED HELP FOR SHOOTER

SpyCoderX wrote:

Use these blocks to detect if your are touching the edge or an enemy:
<touching [Enemy v] ?>
<touching [edge v] ?>
They said off screen, and most sensing blocks related to touching don't work off screen, this includes sprite to sprite collision.

The only reliable method to do so would be use math to get the trajectory (eg, the direction and speed) of an bullet and the position of the enemy to determine whenever an enemy is hit by an offscreen bullet or not.

post #1000 post #100 i help in the forums post #1 post #500 0 second ninja
I recommend reading jvvg's essay about the scratch team before complaining, as it may change your opinion and provide insight on the topic.

coming soon :)


invalidaccess
Scratcher
100+ posts

NEED HELP FOR SHOOTER

Malicondi wrote:

SpyCoderX wrote:

Use these blocks to detect if your are touching the edge or an enemy:
<touching [Enemy v] ?>
<touching [edge v] ?>
They said off screen, and most sensing blocks related to touching don't work off screen, this includes sprite to sprite collision.

The only reliable method to do so would be use math to get the trajectory (eg, the direction and speed) of an bullet and the position of the enemy to determine whenever an enemy is hit by an offscreen bullet or not.
and how do i do that or is there any tutorial
weeeeeeeyay5
Scratcher
21 posts

NEED HELP FOR SHOOTER

Do this:
when green flag clicked
forever
repeat until <<touching [enemy v] ?> or <touching [edge v] ?>>
move (your number) steps


end
end

end
end
For the enemy:
when green flag clicked
forever
if <touching [bullet v] ?> then
hide

end
end
or for a clone do “if touching bullet delete this clone”

Hello! This is a wall to protect my signature to toxic comments and people. If you see said toxic people, click the (Report!) button. [note: it may not be that color]

when green flag clicked
forever
Imagine::custom
Program::custom
Share::custom
“Logic will get you from A to Z. Imagination will get you everywhere.” - Albert Einstein
“You can't do anything if you don't try.” - weeeeeeeyay5
“I set my time machine to one week before the world ends. It said I can’t go to the past.” - 1 day ago by unknown.

Some cool things:
say (set pen color to #ff0000)
BigNate469
Scratcher
1000+ posts

NEED HELP FOR SHOOTER

If you have the direction, then you need trigonometry to find the slope of the line, and then perform some math to figure out if an enemy is hit by the line. There might not be one good tutorial for this.

Highlight any part of this signature and press ctrl+shift+down arrow to see the rest of it
forever
if <person asks [what's a signature] :: sensing> then
Redirect to [https://en.scratch-wiki.info/wiki/Signature] :: motion
end
end
Please read the list of Officially Rejected Suggestions before posting a suggestion for Scratch! 100th post
This signature is designed to be as helpful as possible.
View all of the topics you've posted in:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=topics
View all of your posts:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=posts
Forum tips:
Don't post in topics where the latest post is over ~2 months old, unless you have something critical to add. Especially in topics that are several years old- it isn't helpful, and is known as necroposting.
Don't post unrelated things in topics, including questions of your own. Make a new topic for your questions.
You can use the
 [color=color name or hexadecimal value here] and [/color] 
tags to color text.
Lesser-known Scratch URLs:
https://scratch.mit.edu/projects/PROJECT ID HERE/remixtree (replace “PROJECT ID HERE” with project id number. Shows all the remixes of the project, and the remixes of those projects, and the remixes of those projects, and so on, as a chart. Link currently redirects to one of my projects)
View a larger list at: https://scratch.mit.edu/discuss/topic/542480/
Why @Paddle2See's responses are so often identical: https://scratch.mit.edu/discuss/topic/762351/
1000th post
Malicondi
Scratcher
1000+ posts

NEED HELP FOR SHOOTER

BigNate469 wrote:

If you have the direction, then you need trigonometry to find the slope of the line, and then perform some math to figure out if an enemy is hit by the line. There might not be one good tutorial for this.
there is no trigonometry required in finding a slope or velocity, only for finding the direction of a slope. If you remember slope is just this:
x2 - x1
———
y2 - y1
and an undefined slope is just straight up or down. Same can be calculated for velocity, just without division so x velocity would be this:
x2 - x1
and y velocity would be this:
y2 - y1
where x1 and y1 was its last position, and x2 and y2 are it's new position. From there, you can predict whenever the slope will intercept with the enemies position (more algebra) and determine if the enemy should die or not.

post #1000 post #100 i help in the forums post #1 post #500 0 second ninja
I recommend reading jvvg's essay about the scratch team before complaining, as it may change your opinion and provide insight on the topic.

coming soon :)


BigNate469
Scratcher
1000+ posts

NEED HELP FOR SHOOTER

Malicondi wrote:

BigNate469 wrote:

If you have the direction, then you need trigonometry to find the slope of the line, and then perform some math to figure out if an enemy is hit by the line. There might not be one good tutorial for this.
there is no trigonometry required in finding a slope or velocity, only for finding the direction of a slope. If you remember slope is just this:
x2 - x1
———
y2 - y1
and an undefined slope is just straight up or down. Same can be calculated for velocity, just without division so x velocity would be this:
x2 - x1
and y velocity would be this:
y2 - y1
where x1 and y1 was its last position, and x2 and y2 are it's new position. From there, you can predict whenever the slope will intercept with the enemies position (more algebra) and determine if the enemy should die or not.
True. But if you already have a direction, and need a slope, then you need trig. I don't know how this project works, but a lot of projects rely on sprite direction rather than the slope of a line to point at things.

Highlight any part of this signature and press ctrl+shift+down arrow to see the rest of it
forever
if <person asks [what's a signature] :: sensing> then
Redirect to [https://en.scratch-wiki.info/wiki/Signature] :: motion
end
end
Please read the list of Officially Rejected Suggestions before posting a suggestion for Scratch! 100th post
This signature is designed to be as helpful as possible.
View all of the topics you've posted in:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=topics
View all of your posts:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=posts
Forum tips:
Don't post in topics where the latest post is over ~2 months old, unless you have something critical to add. Especially in topics that are several years old- it isn't helpful, and is known as necroposting.
Don't post unrelated things in topics, including questions of your own. Make a new topic for your questions.
You can use the
 [color=color name or hexadecimal value here] and [/color] 
tags to color text.
Lesser-known Scratch URLs:
https://scratch.mit.edu/projects/PROJECT ID HERE/remixtree (replace “PROJECT ID HERE” with project id number. Shows all the remixes of the project, and the remixes of those projects, and the remixes of those projects, and so on, as a chart. Link currently redirects to one of my projects)
View a larger list at: https://scratch.mit.edu/discuss/topic/542480/
Why @Paddle2See's responses are so often identical: https://scratch.mit.edu/discuss/topic/762351/
1000th post
Malicondi
Scratcher
1000+ posts

NEED HELP FOR SHOOTER

BigNate469 wrote:

True. But if you already have a direction, and need a slope, then you need trig. I don't know how this project works, but a lot of projects rely on sprite direction rather than the slope of a line to point at things.
If you already have the direction you can just move like this:
change [x v] by (([sin v] of (direction)) * (x velocity))
change [y v] by (([cos v] of (direction)) * (y velocity))
But using velocity already does this which is why i said you don't really need trigonometry. (also this is basically just the “move in () steps” block.

Last edited by Malicondi (March 29, 2024 20:29:57)


post #1000 post #100 i help in the forums post #1 post #500 0 second ninja
I recommend reading jvvg's essay about the scratch team before complaining, as it may change your opinion and provide insight on the topic.

coming soon :)


invalidaccess
Scratcher
100+ posts

NEED HELP FOR SHOOTER

Malicondi wrote:

BigNate469 wrote:

True. But if you already have a direction, and need a slope, then you need trig. I don't know how this project works, but a lot of projects rely on sprite direction rather than the slope of a line to point at things.
If you already have the direction you can just move like this:
change [x v] by (([sin v] of (direction)) * (x velocity))
change [y v] by (([cos v] of (direction)) * (y velocity))
But using velocity already does this which is why i said you don't really need trigonometry. (also this is basically just the “move in () steps” block.
i have a project using that method
here: https://scratch.mit.edu/projects/990213833/ (scripts in the bullet sprite)
if this what you mean imma use it

Powered by DjangoBB