Discuss Scratch
- InsaneMasterDJ
- New to Scratch
3 posts
Make a sprite shoot a projectile
Hello all.
I am fairly new to scratch and need help making my sprite shoot a projectile going in a straight line from where the mouse is pointing. It needs to fire when the player presses the left mouse button. Thanks
I am fairly new to scratch and need help making my sprite shoot a projectile going in a straight line from where the mouse is pointing. It needs to fire when the player presses the left mouse button. Thanks
- InsaneMasterDJ
- New to Scratch
3 posts
Make a sprite shoot a projectile
I forgot to mention it needs to fire out of a gun, which is attached to my sprite. My sprite main character follows the mouse pointer.
- GizzB
- Scratcher
100+ posts
Make a sprite shoot a projectile
I forgot to mention it needs to fire out of a gun, which is attached to my sprite. My sprite main character follows the mouse pointer.
First add a costume to the gun and call it “bullet”, make the bullet look like whatever you like.
Then, on the gun:
when green flag clicked
forever
if <mouse down?> then
create clone of [myself v]
end
end
Also add this script to your gun.
when I start as a clone
switch costume to [bullet v]
point towards [mouse-pointer v]
repeat until <<touching [edge v] ?> or <touching [ENEMYSPRITENAMEHERE v] ?>>
move (10) steps //Change 10 to whatever you like, the higher the number the faster the bullet
end
if <not <touching [edge v] ?>> then
broadcast [shot_enemy v]
end
delete this clone
Then to check if the enemy has been shot:
when I receive [shot_enemy v]
...
Last edited by GizzB (April 23, 2015 08:27:53)
- Tweenager13
- Scratcher
1 post
Make a sprite shoot a projectile
Well, what i wanna know how you make a sprite shoot to the left side. When you program it, it always shoots to the left side.
- deck26
- Scratcher
1000+ posts
Make a sprite shoot a projectile
Can you share what you have? I'm wondering if you're using a costume facing left rather than telling the firing sprite to point left.
- racer2014
- Scratcher
29 posts
Make a sprite shoot a projectile
Make a clone, then use the clone as the bullet, and have it repeatedly move in the direction of your choice.
- GrithonIsAwesome
- Scratcher
3 posts
Make a sprite shoot a projectile
WARNING! THIS IS NOT TESTED!
when green flag clicked
forever
if <mouse down> then
create clone of
end
Then, for the bullet sprite, make a variable called speed.
then say -
set [ speed ] to [1]
when I start as a clone
point towards [ mousepointer]
repeat until <touching edge or (target)>
move ( speed ) steps
if < touching edge or (target)> then
set [ speed ] to [1]
end
Then it will move faster the farther it goes.
- asivi
- Scratcher
1000+ posts
Make a sprite shoot a projectile
WARNING! THIS IS NOT TESTED!
when green flag clicked
forever
if <mouse down> then
create clone of
end
Then, for the bullet sprite, make a variable called speed.then say -
set [ speed ] to [1]
when I start as a clone
point towards [ mousepointer]
repeat until <touching edge or (target)>
move ( speed ) steps
if < touching edge or (target)> then
set [ speed ] to [1]
end
Then it will move faster the farther it goes.[/quote]
Hi, you have forgot to delete the clone or say how to reuse it.
- GrithonIsAwesome
- Scratcher
3 posts
Make a sprite shoot a projectile
oops
Last edited by GrithonIsAwesome (April 8, 2017 14:10:59)
- deck26
- Scratcher
1000+ posts
Make a sprite shoot a projectile
Please don't spam - it is reportable. vbdj:kvdo;sdkd
- jagooodrich
- New to Scratch
3 posts
Make a sprite shoot a projectile
Thank you, but when I switch scenes after shooting the projectiles, they travel with me in a small clump and they make my game lag. The projectiles also move with my main sprite when i move.
- electrogame02
- Scratcher
500+ posts
Make a sprite shoot a projectile
There’s a lot of ways to make player/enemy shooting.
Little buggy but simple way is this one:
Little buggy but simple way is this one:
set [ I shoot from x v] to (x position)
set [ i shoot from y v] to (y position)
create clone of [ bullet v]
when I start as a clone
go to x: (i shoot from x) y: (i shoot from y)
M O N K E .
- jagooodrich
- New to Scratch
3 posts
Make a sprite shoot a projectile
nvm, I didn't see the delete clone component. Thanks a lot for this script.
- electrogame02
- Scratcher
500+ posts
Make a sprite shoot a projectile
If this can help you, see this project: https://scratch.mit.edu/projects/178556363/
M O N K E .
- deck26
- Scratcher
1000+ posts
Make a sprite shoot a projectile
https://scratch.mit.edu/projects/178556363/Please don't necropost - this topic is old. If this can help you, see this project:
- Rutilant
- Scratcher
7 posts
Make a sprite shoot a projectile
I forgot to mention it needs to fire out of a gun, which is attached to my sprite. My sprite main character follows the mouse pointer.
First add a costume to the gun and call it “bullet”, make the bullet look like whatever you like.
Then, on the gun:when green flag clicked
forever
if <mouse down?> then
create clone of [myself v]
end
end
Also add this script to your gun.when I start as a clone
switch costume to [bullet v]
point towards [mouse-pointer v]
repeat until <<touching [edge v] ?> or <touching [ENEMYSPRITENAMEHERE v] ?>>
move (10) steps //Change 10 to whatever you like, the higher the number the faster the bullet
end
if <not <touching [edge v] ?>> then
broadcast [shot_enemy v]
end
delete this clone
Then to check if the enemy has been shot:when I receive [shot_enemy v]
...
I doubt this discussion is still active, but for some reason a random bullet follows my mouse, and when I let go it moves the direction it was going. Help?
//Yo. I'm Rutilant but call me Kris. //