NEED HELP FOR SHOOTER

id: 751031

category: Help with Scripts

posts: 13

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
SpyCoderX SpyCoderX loading

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

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 Malicondi loading

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.

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
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”
BigNate469 BigNate469 loading
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.
Malicondi Malicondi loading

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.
BigNate469 BigNate469 loading

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.
Malicondi Malicondi loading

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.

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