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

#1 2010-12-31 11:29:35

Robot_Maniac
Scratcher
Registered: 2010-11-22
Posts: 56

How to bounce of sprites

I'm having trouble. I'm trying to make a ball bounce off a sprite, but it's not working! I'm using the [blocks]<if on edge, bounce>[/blocks] block. But it's not working! Help!


Math Trick of the Week: Choose any three digit number that's one digit is at least 2 less that the tens digit and the tens digit at least 2 less than the hundreds. Then, reverse the digits and subtract. Then, reverse the digits in the answer and add. You should get 1089.

Offline

 

#2 2010-12-31 15:51:19

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How to bounce of sprites

The "if on edge, bounce" block only works if the sprite is touching the edge of the screen.  I have a project that shows how to make a laser bounce off of a wall though: http://scratch.mit.edu/projects/MoreGamesNow/755062

This code should work (I haven't tested it though): Forever if touching wall
x-velocity=x-velocity*-1

Of course, this assumes you know how to use x-velocity to change the speed of a sprite.  If not look at this (sorry if it looks like javascript)

When Flag Pressed
Forever
{
if (right arrow pressed)
{
change x-velocity by 0.1
}
if (left arrow pressed)
{
change x-velocity by -0.1
}
set x-velocity to x-velocity*0.9
}


You may need to play with the 0.9 and the 0.1 numbers to get the correct speed and friction.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2010-12-31 16:35:38

Robot_Maniac
Scratcher
Registered: 2010-11-22
Posts: 56

Re: How to bounce of sprites

yeah, but I want a ball to bounce off a wall.


Math Trick of the Week: Choose any three digit number that's one digit is at least 2 less that the tens digit and the tens digit at least 2 less than the hundreds. Then, reverse the digits and subtract. Then, reverse the digits in the answer and add. You should get 1089.

Offline

 

#4 2010-12-31 16:51:21

Robot_Maniac
Scratcher
Registered: 2010-11-22
Posts: 56

Re: How to bounce of sprites

MoreGamesNow wrote:

The "if on edge, bounce" block only works if the sprite is touching the edge of the screen.  I have a project that shows how to make a laser bounce off of a wall though: http://scratch.mit.edu/projects/MoreGamesNow/755062

This code should work (I haven't tested it though): Forever if touching wall
x-velocity=x-velocity*-1

Of course, this assumes you know how to use x-velocity to change the speed of a sprite.  If not look at this (sorry if it looks like javascript)

When Flag Pressed
Forever
{
if (right arrow pressed)
{
change x-velocity by 0.1
}
if (left arrow pressed)
{
change x-velocity by -0.1
}
set x-velocity to x-velocity*0.9
}


You may need to play with the 0.9 and the 0.1 numbers to get the correct speed and friction.

It would be easier to read if you inserted the Scratch blocks...


Math Trick of the Week: Choose any three digit number that's one digit is at least 2 less that the tens digit and the tens digit at least 2 less than the hundreds. Then, reverse the digits and subtract. Then, reverse the digits in the answer and add. You should get 1089.

Offline

 

#5 2010-12-31 19:27:20

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How to bounce of sprites

Like This?

Last edited by MoreGamesNow (2010-12-31 19:28:47)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#6 2010-12-31 20:16:18

Robot_Maniac
Scratcher
Registered: 2010-11-22
Posts: 56

Re: How to bounce of sprites

Yes! Just like that!


Math Trick of the Week: Choose any three digit number that's one digit is at least 2 less that the tens digit and the tens digit at least 2 less than the hundreds. Then, reverse the digits and subtract. Then, reverse the digits in the answer and add. You should get 1089.

Offline

 

#7 2010-12-31 22:22:57

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How to bounce of sprites

I don't know if you've downloaded the script but it is basically this:

<when green flag clicked>
<go to x sad  0 )y sad  0 )>
<set{ x-velocity }to( <pick random( -4 )to( 4 )>
<set{ y-velocity }to( 0 )>
<forever>
<if><touching[ floor ]?>
<set{ y-velocity }to( 0 )>
<else>
<change{ y-velocity }by( -0.1 )>
<end>
<if><< <touching[ Wall1 ]?> <or> <touching[ Wall2 ]?> >>
<set{ x-velocity }to( x-velocity*-1 )>
<end>
<change y by( y-velocity )>
<change x by( x-velocity )>
<end>


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#8 2011-01-01 12:27:05

Robot_Maniac
Scratcher
Registered: 2010-11-22
Posts: 56

Re: How to bounce of sprites

oh, ok! Thanks!


Math Trick of the Week: Choose any three digit number that's one digit is at least 2 less that the tens digit and the tens digit at least 2 less than the hundreds. Then, reverse the digits and subtract. Then, reverse the digits in the answer and add. You should get 1089.

Offline

 

#9 2011-01-08 19:00:44

coblet
New Scratcher
Registered: 2010-12-28
Posts: 2

Re: How to bounce of sprites

<set y to( <set y to( <set y to( <set pen shade to(

Offline

 

Board footer