NEED HELP FOR SHOOTER
id: 751031
category: Help with Scripts
posts: 13
invalidaccess
loading
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
invalidaccess
loading
https://scratch.mit.edu/projects/984025811/ here's the project
SpyCoderX
loading
Use these blocks to detect if your are touching the edge or an enemy: 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
<touching [Enemy 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).
<touching [edge v] ?>
invalidaccess
loading
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
loading
NEED HELP FOR SHOOTERUse these blocks to detect if your are touching the edge or an enemy: 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<touching [Enemy 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).
<touching [edge v] ?>
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
loading
They said off screen, and most sensing blocks related to touching don't work off screen, this includes sprite to sprite collision. Use these blocks to detect if your are touching the edge or an enemy:<touching [Enemy v] ?>
<touching [edge v] ?>
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.
invalidaccess
loading
and how do i do that or is there any tutorialThey said off screen, and most sensing blocks related to touching don't work off screen, this includes sprite to sprite collision. Use these blocks to detect if your are touching the edge or an enemy:<touching [Enemy v] ?>
<touching [edge v] ?>
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.
weeeeeeeyay5
loading
Do this:
when green flag clickedFor the enemy:
forever
repeat until <<touching [enemy v] ?> or <touching [edge v] ?>>
move (your number) steps
end
end
end
end
when green flag clickedor for a clone do “if touching bullet delete this clone”
forever
if <touching [bullet v] ?> then
hide
end
end
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
loading
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: 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.
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
loading
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.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: 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.
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.
Malicondi
loading
If you already have the direction you can just move like this: 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.
change [x v] by (([sin v] of (direction)) * (x 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.
change [y v] by (([cos v] of (direction)) * (y velocity))
invalidaccess
loading
i have a project using that methodIf you already have the direction you can just move like this: 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.change [x v] by (([sin v] of (direction)) * (x 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.
change [y v] by (([cos v] of (direction)) * (y velocity))
here: https://scratch.mit.edu/projects/990213833/ (scripts in the bullet sprite)
if this what you mean imma use it