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

#1 2009-08-23 11:41:50

Scratchy07
Scratcher
Registered: 2009-08-23
Posts: 4

if touching sprite 2...

hello,
im new in scratch and wanted to make a little shooter, I have my Charakter (Sprite 1) the bullet (sprite 2), a stripe (Sprite 3) and an enemy (Sprite4)

The script of the enemy is:

when green flag clicked
go to xx : xx (start position)
if   < touching sprite 2 >
   go to xxx:xxx (start position)
else
   glide to yy:yy (position of my charakter)

So if I fire my weapon and the bullet hits the enemy the enemy had to got back to the starting position, or not?
But the enemy touches the bullet but go on gliding  sad

If u dont know what im talking abaout, thats my project:
http://rapidshare.com/files/270579195/ww2.sb.html

Offline

 

#2 2009-08-23 11:58:33

Scratchy07
Scratcher
Registered: 2009-08-23
Posts: 4

Re: if touching sprite 2...

is it possible that two moving objects cant touch each other? Because if enemy runs into my bullet (not fired) he returns to the start but if the bullet moves the enemy goes on...

Offline

 

#3 2009-08-23 14:47:51

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: if touching sprite 2...

Here are a couple of possibilities.  (1) your script actually reads: go to the start position and if, at that position, you're touching Sprite 2, then do something.  But what are the odds that right when the enemy is at its start position it's going to be touching the bullet?  Probably not. So it might work to rewrite the script so that *whenever* the enemy touches Sprite 2, then it would do something. The "forever" command might work for that. ______(2) in my limited experience the "glide" command can't really be interrupted along the way.  (It glides, and *then* it checks to see if it's touching something.)  It seems to work better to use a "repeat" where into each repetition you build the condition "if touching Sprite 2."  That way the script constantly checks to see if Sprite 2 is being touched. So you would have a script that says:
     Repeat ()
          Move 5 steps
          Wait 0.1 seconds
          If touching Sprite 2
                 go to.....
               else
                 go to.....
Sorry I haven't used the nice Scratch blocks to write the script but I haven't learned how yet!  :-/

Offline

 

#4 2009-08-23 16:46:38

Scratchy07
Scratcher
Registered: 2009-08-23
Posts: 4

Re: if touching sprite 2...

hey, the second version works, thank you very much  wink

Offline

 

Board footer