This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-03-08 15:28:26

redadder1
New Scratcher
Registered: 2013-03-08
Posts: 1

Shooting

Can someone please give me the scripts on how to shoot a bullet

Offline

 

#2 2013-03-08 15:44:09

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: Shooting

Hmm... That is a rather complex thing, but i have an idea:

Put this in the bullet sprite:

when i receive [Game Start v]
go to x: < [x position v] of [player v] > y: (< [y position v] of [player v] > - [However much you need] )
hide

Okay, so now it's going to the player, and if you adjust the y right, to the player's gun.
Now, we need it to always face the direction of the player, so:

when i receive [Game Start v]
forever
point in direction < [direction v] of [player v] >
end
So that means which ever way your player is facing, the bullet will face. NOTE: This also means that you need to have the player point in the direction he's moving in.

Then, you need it to fire of course. So put in the bullet:

when i receive [Game Start v]
forever
if <key [space v] pressed?>
if < not  <(shooting?) = [yes]> > 
set [shooting? v] to [yes]
show
repeat (100)
move (20) steps
if <touching? [edge v]>
hide
end
if <touching? [enemy v]>
hide
end
end
go to x: < [x position v] of [player v] > y:  (< [y position v] of [player v] >  - [what ever you need] )
set [shooting? v] to [no]
end
end
you need to create a variable called "Shooting?" to make this work, and put a script like this:

when gf clicked
set [shooting? v] to [no]
There is another way to do this, if this one doesn't work for you.

Hope that helps,

CAA14

Last edited by CAA14 (2013-03-08 15:48:50)

Offline

 

Board footer