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

#1 2012-06-26 14:34:58

Hariex
New Scratcher
Registered: 2012-06-25
Posts: 10

Help Needed!

I am attempting to create a rebound/bouncing script, where an object would bounce off a wall. My attempt is not working, and due to being a noob I have not yet mastered the Scratchblocks code, thus, I can not show you my not-working script. Any help?

Offline

 

#2 2012-06-26 14:39:04

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: Help Needed!

You can use this:

when gf clicked
forever
 if on edge, bounce
end

Last edited by SciTecCf (2012-06-26 14:39:22)


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&display=small

Offline

 

#3 2012-06-26 14:48:28

Hariex
New Scratcher
Registered: 2012-06-25
Posts: 10

Re: Help Needed!

I believe this would be better suited for the walls of the Sprite stage. My Scratch stage is a building layout, and I need an object to bounce off the buildings. Do you have any suggestions?

Offline

 

#4 2012-06-26 14:57:52

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Help Needed!

when gf clicked
forever if <touching color [#000000]?>
point in direction ((direction)*(-1))


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#5 2012-06-26 15:05:51

Hariex
New Scratcher
Registered: 2012-06-25
Posts: 10

Re: Help Needed!

Doesn't work, I'm afraid.

Offline

 

#6 2012-06-26 15:12:35

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Help Needed!

Hariex wrote:

Doesn't work, I'm afraid.

you do know how to do color sensing right?


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#7 2012-06-26 15:34:27

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

Re: Help Needed!

The exact code depends on what exactly you're doing.  Do you want accurate redirection of velocity, are the walls all parallel and perpendicular, and are you moving via acceleration or constant velocity?

when gf clicked
forever
change x by (x-vel)
if<touching [wall v]?>
set [x-vel v] to ((-1)*(x-vel))
change x by (x-vel)
end
change y by (y-vel)
if<touching [wall v]?>
set [y-vel v] to ((-1)*(y-vel))
change y by (y-vel)
end

Last edited by MoreGamesNow (2012-06-26 15:36:14)


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

Offline

 

#8 2012-06-26 15:43:35

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: Help Needed!

http://scratch.mit.edu/projects/fg123_tests/2637559

Here's a simple way to make the sprite bounce off a wall.


Hai.

Offline

 

Board footer