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

#1 2009-07-01 22:47:04

greenflash
Scratcher
Registered: 2009-05-27
Posts: 1000+

How to get a Sprite bounce off another Sprite!

I've seen a lot of people ask for this. It's information in high demand. It's been suggested as a new scratch block too. But for now, this is the script to use if you want to get one sprite bounce off another:

[blocks]
<when green flag clicked>
<forever if><touching[ something to bounce off ]>
<turn cw( 180 )degrees>
<end>

[/blocks]

This works if you have a motion block in another script. If you don't you can add motion into the above script like this:

[blocks]
<when green flag clicked>
<forever>
<if><touching[  something to bounce off ]>
<turn cw( 180 )degrees>
<end>
<if><key[ up arrow ]pressed?>
<change y by( 10 )>
<end>
<if><key[down arrow ]pressed?>
<change y by(-10)>
<end>
<if><key[ left arrow ]pressed?>
<change x by(-10)>
<end>
<if><key[right arrow  ]pressed?>
<change x by(-10)>
<end>
<end>
[/blocks]

This creates a bouncing sprite that can be moved with the arrow keys!

Hope you found what your looking for!

Scratch On!


http://i48.tinypic.com/2wrkirk.pnghttp://i46.tinypic.com/6r5zk7.pnghttp://i45.tinypic.com/2vtxr1t.png

Offline

 

#2 2009-07-02 12:11:32

Mozaz
Scratcher
Registered: 2009-05-19
Posts: 500+

Re: How to get a Sprite bounce off another Sprite!

Nice one!  smile  Maybe make this into a project so more people can see it in action  smile

Just a little tip, you might want to add a 'wait until not touching sprite' script, because if the sprite your bouncing off is big, it will just keep changing direction.

Last edited by Mozaz (2009-07-02 12:12:46)


http://i33.tinypic.com/15i5fmp.png

Offline

 

Board footer