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

#1 2012-06-24 17:52:28

RCScratch
Scratcher
Registered: 2010-05-26
Posts: 48

How to make a Sprite bounce off of another Sprite easily!

How do you make an object bounce off another object cleanly without it going 180 degrees back every time?

don't post the answer like so -

when gf clicked
repeat until <(timer) > [10]>
  go to [mouse-pointer v]
end
think [Scripts in your posts!] for (6) secs

Last edited by RCScratch (2012-06-24 17:53:03)


http://i736.photobucket.com/albums/xx7/RCScratch/RCSCRatch.gif http://www.danasoft.com/sig/467044211994.jpg

Offline

 

#2 2012-06-24 18:08:33

Molybdenum
Scratcher
Registered: 2012-06-17
Posts: 1000+

Re: How to make a Sprite bounce off of another Sprite easily!

Tell that to a Koch snowflake.

Google it. It means you can't do that without knowing the shape of the to-be-bounced-off sprite.

I guess you could do it with sensors though.


"The Enrichment Center is required to remind you that you will be baked, and then there will be cake."
(|Balls and Platforms: Stay on!|) (|NaOS-H: An operating system... Or is it?|)

Offline

 

#3 2012-06-24 18:36:06

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

Re: How to make a Sprite bounce off of another Sprite easily!

If all of the walls are 90 degrees it is relatively easy, but, as Molybdenum said, for more complex scenarios you need to know the slope at the point of contact of both objects.

If you're not using velocity, it is much easier (storing your previous position before movement is a common way).

Finally, what form of input are you using?  Keyboard?  Mouse?  If you want the sprite to follow the mouse unless it hits a wall, I have a some-what workable script on another thread that I could find for you.


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

Offline

 

#4 2012-06-25 02:23:39

JH1010
Scratcher
Registered: 2012-05-31
Posts: 1000+

Re: How to make a Sprite bounce off of another Sprite easily!

If you are making an animation then you could just do this:

Sprite 1 (the moving sprite):

when gf clicked
go to x (0) y (-100)
glide (1) seconds to x (100) y (0)
glide (1) seconds to x (0) y (100)
Sprite 2 (the stationary sprite):

when gf clicked
go to x (100) y (0) // The sprite would have to have an x co-ordinate of slightly more than 100 depending on its size.
Hope this helps.

Offline

 

Board footer