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

InsaneMasterDJ wrote:

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.
gabsters101
New to Scratch
1 post

Make a sprite shoot a projectile

Thanks GizzB
asivi
Scratcher
1000+ posts

Make a sprite shoot a projectile

GrithonIsAwesome wrote:

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.
asivi
Scratcher
1000+ posts

Make a sprite shoot a projectile

Fine! Another * with a trap. ^^^^
GrithonIsAwesome
Scratcher
3 posts

Make a sprite shoot a projectile

oops

Last edited by GrithonIsAwesome (April 8, 2017 14:10:59)

Toddo_100
Scratcher
1 post

Make a sprite shoot a projectile

Thankyou
kullen_playz
Scratcher
1 post

Make a sprite shoot a projectile

vbdj:kvdo;sdkd
deck26
Scratcher
1000+ posts

Make a sprite shoot a projectile

kullen_playz wrote:

vbdj:kvdo;sdkd
Please don't spam - it is reportable.
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:

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

electrogame02 wrote:

If this can help you, see this project: https://scratch.mit.edu/projects/178556363/
Please don't necropost - this topic is old.
Rutilant
Scratcher
7 posts

Make a sprite shoot a projectile

GizzB wrote:

InsaneMasterDJ wrote:

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

Powered by DjangoBB