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

#1 2007-05-22 03:03:34

anagramster
Scratcher
Registered: 2007-05-19
Posts: 2

bounce

The "if on edge, bounce" is handy, but I'd like a simple extension:
"if on color/sprite/pointer/etc bounce" which would "do the right thing", namely determine the new vector based solely on the speed and direction of the collision.
Yes, it could get a bit complicated.  For example, could you embed an "or" expression so that a collision with black or blue would trigger.  The same event need to be registered on the other sprite in order to make the collision appear reflected.
It would make so many of the games and other things more realistic.  Being able to scale the properties could explore elasticity of collisions.

Maybe "if on [contact] bounce [value]%" could be used to simulate collisions of objects of different mass.

Anyways, the point is to get the new speed and direction set correctly, assuming spherical surfaces.

Offline

 

#2 2007-05-22 13:31:53

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: bounce

If you want physics-based simulation, you have to write it yourself.

You can do it in scratch, for points or spheres, but bouncing off a straight line that is not at a convenient angle (like a multiple of 45 degrees) is almost impossible without trig functions or sqrt.

Prebuilding a physics simulation is not the point of scratch, but it would be nice to have the tools we need to do it ourselves.

Offline

 

#3 2007-05-22 18:23:33

mungojelly
Scratcher
Registered: 2007-05-19
Posts: 35

Re: bounce

You can't make Scratch have realistic physics very easily, but you can make it have SOME sort of physics.  You can make rules about what happens when various objects get near each other or touch each other.  It's a pain because there's not really a way to make general rules.  But you can go into each Sprite and say, OK, if you get too close to this, bounce away, if you're trying to go through this, don't be able to, etc.

What is easy is to make complicated physics.  It's as easy to make objects react in complicated ways to each other as it is to make them react all in the same simple reasonable way.  wink   But I mean you can have things gravitate to other things, or stick to them, or start to vibrate strangely in each other's presence.  Reactivity is more available than coherency!

<3

Offline

 

#4 2007-05-22 23:59:50

Canthiar
Scratcher
Registered: 2007-05-16
Posts: 100+

Re: bounce

It would be nice if scratch had more built in math functions, but you have the power to make your own. 

Here's an example of the cosine function in scratch: http://scratch.mit.edu/projects/Canthiar/6123 

This program uses a square root written in scratch:
http://scratch.mit.edu/projects/Canthiar/3915

Bouncing is pretty easy with just about any surface.  All you need is the normal of the surface at collision (N) and the velocity of the object (V) and you can get the reflected velocity (R) with this simple formula:  R = 2 * N * ( -V dot N ) + V.  This requires that your velocity and normal be stored as vectors.  If you're using Scratch's direction and distance commands then you will need to use a sine and cosine to get the resulting vectors.

Edit for spelling

Last edited by Canthiar (2007-05-23 00:00:41)

Offline

 

#5 2007-05-23 22:52:43

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: bounce

Please add these to the Math Connections gallery,
http://scratch.mit.edu/galleries/134

Offline

 

#6 2007-05-26 02:22:22

Canthiar
Scratcher
Registered: 2007-05-16
Posts: 100+

Re: bounce

kevin_karplus wrote:

Please add these to the Math Connections gallery,
http://scratch.mit.edu/galleries/134

done

Offline

 

Board footer