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

#1 2011-01-10 17:15:00

-GizzardGulp-
Scratcher
Registered: 2010-03-05
Posts: 100+

How do you make sprites bounce realistically off of other sprites?

I only need a code that makes bouncing off of vertical or horizontal surfaces, nothing fancy like side-ways. It needs to be the right thing exactly, no randomness! Thanks in advance.


http://i1118.photobucket.com/albums/k607/Max_Levine/SnoutmolStudios.png

Offline

 

#2 2011-01-10 18:34:29

pety45
Scratcher
Registered: 2010-05-07
Posts: 10

Re: How do you make sprites bounce realistically off of other sprites?

this is  all            <glide(  )secs to x sad   )y sad

Offline

 

#3 2011-01-10 19:50:13

-GizzardGulp-
Scratcher
Registered: 2010-03-05
Posts: 100+

Re: How do you make sprites bounce realistically off of other sprites?

pety45 wrote:

this is  all            <glide(  )secs to x sad   )y sad

-_-

No, that is not all, pety45.

I mean BOUNCING off of sprites as in:
Pong

i have a brainfart and cant think of anything else


http://i1118.photobucket.com/albums/k607/Max_Levine/SnoutmolStudios.png

Offline

 

#4 2011-01-11 12:00:02

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: How do you make sprites bounce realistically off of other sprites?

Well for pong, the ball script could either be:

When flag Clicked
  Forever
    change x by (xvel)
    change y by (yvel)
    if (touching (paddle))
      set (yvel) to ((yvel)*-1)
  end

You'd also ad a if abs(x)>238 so on and so forth

Another way is:

When flag Clicked
  forever
    move (5) steps
    if on edge, bounce
    if touching (paddle)
     set direction to ( (180-(direction) )*-1)
  end

That should work... one sec...

Last edited by AtomicBawm3 (2011-01-11 12:25:36)


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#5 2011-01-11 15:52:51

ian528
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: How do you make sprites bounce realistically off of other sprites?

Look here.Make sure to download the project and read the comments in it!!!  wink

Last edited by ian528 (2011-01-11 15:53:18)

Offline

 

#6 2011-01-11 20:33:18

MiffinTheMuffin
Scratcher
Registered: 2010-12-11
Posts: 1000+

Re: How do you make sprites bounce realistically off of other sprites?

<when green flag clicked>
<if><touching[
<point in direction( (( <direction> <+> 180 ))
<end>


http://i.imgur.com/FDvbV.png

Offline

 

#7 2011-01-11 21:05:39

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: How do you make sprites bounce realistically off of other sprites?

Try looking at this or thissmile


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#8 2011-01-11 21:11:08

-GizzardGulp-
Scratcher
Registered: 2010-03-05
Posts: 100+

Re: How do you make sprites bounce realistically off of other sprites?

MiffinTheMuffin wrote:

<when green flag clicked>
<if><touching[
<point in direction( (( <direction> <+> 180 ))
<end>

thats not perfect its random


http://i1118.photobucket.com/albums/k607/Max_Levine/SnoutmolStudios.png

Offline

 

Board footer