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

#1 2012-01-27 19:40:20

AllButSimilar
New Scratcher
Registered: 2012-01-09
Posts: 20

Continuos Bouncing Off Sprite?

I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?

Offline

 

#2 2012-01-27 20:23:45

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

Re: Continuos Bouncing Off Sprite?

AllButSimilar wrote:

I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?

So you want a bouncing script that would mimic what the edge would normally do?  Is your sprite using direction or x and y velocities?

DIRECTION

when gf clicked
forever
   move (x) steps
   if <touching [big sprite v] ?>
      if <([abs v] of (x position)) > [200]>
         point in direction ((direction) * [-1])
      else
         point in direction ((((direction) - (90)) * (-1)) + (90))
      end
   end
end
That should work...tell me if it doesn't.

X, Y VELOCITIES

when gf clicked
forever
   change x by (x velocity)
   change y by (y velocity)
   if <touching [big sprite v] ?>
      if <([abs v] of (x position)) > [200]>
         set [x velocity v] to ((x velocity) * (-1))
      else
          set [y velocity v] to ((y velocity) * (-1))
      end
   end
end
That should also work...

fixed script formatting - I couldn't resist :3 --JSO

Last edited by JSO (2012-01-28 05:35:34)


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

Offline

 

#3 2012-01-27 20:39:46

slayerrobe7
Scratcher
Registered: 2011-06-24
Posts: 500+

Re: Continuos Bouncing Off Sprite?

the one i use and scratch used in sample pong is

when gf clicked
forever if <touching [sprite]>
point in direction < [180] - (direction)
move [5] steps
turn ccw <pick random [-20] to [20]> degrees


!!!When it comes to Scratch2.0 I am totally like freaking out!!!

Offline

 

#4 2012-01-27 20:57:09

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Continuos Bouncing Off Sprite?

Here is a slightly fixed version of AtomicBawm3's scripts:

DIRECTION

when gf clicked
forever
   move (x) steps
   if <touching [big sprite v]?>
      if <([abs v] of (x position)) > (200)>
         point in direction (<direction> * (-1))
      else
         point in direction (<<<direction> - (90)> * (-1)> + (90))
      end
   end
end
X, Y VELOCITIES

when gf clicked
forever
   change x by (x velocity)
   change y by (y velocity)
   if <touching [big sprite v]?>
      if <([abs v] of (x position)) > (200)>
         set [x velocity] to <(x velocity) * (-1)>
      else
          set [y velocity] to <(y velocity) * (-1)>
      end
   end
end

Last edited by Magnie (2012-01-27 21:12:56)

Offline

 

#5 2012-01-27 21:46:04

AllButSimilar
New Scratcher
Registered: 2012-01-09
Posts: 20

Re: Continuos Bouncing Off Sprite?

AtomicBawm3 wrote:

AllButSimilar wrote:

I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?

So you want a bouncing script that would mimic what the edge would normally do?  Is your sprite using direction or x and y velocities?

DIRECTION

when gf clicked
forever
   move (x) steps
   if [touching [big sprite]]
      if <abs(x position) > [200]>
         point in direction (<direction> * [-1])
      else
         point in direction ([[<direction> - [90]] * [-1]] + [90])
      end
   end
end
That should work...tell me if it doesn't.

X, Y VELOCITIES

when gf clicked
forever
   change x by (x velocity)
   change y by (y velocity)
   if [touching [big sprite]]
      if <abs(x position) > [200]>
         set [x velocity] to ((x velocity) * -1)
      else
          set [y velocity] to ((y velocity) * -1)
      end
   end
end
That should also work...

Thanks so much for your help!

Offline

 

#6 2012-01-27 21:56:11

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Continuos Bouncing Off Sprite?

AtomicBawm3 wrote:

DIRECTION

when gf clicked
forever
   move (x) steps
   if <touching [big sprite v]?>
      if <([abs v] of (x position)) > [200]>
         point in direction ((direction) * [-1])
      else
         point in direction ((((direction) - (90)) * (-1)) + (90))
      end
   end
end
X, Y VELOCITIES

when gf clicked
forever
   change x by (x velocity)
   change y by (y velocity)
   if <touching [big sprite v]?>
      if <([abs v] of (x position)) > [200]>
         set [x velocity v] to ((x velocity) * (-1))
      else
          set [y velocity v] to ((y velocity) * (-1))
      end
   end
end

Fixed scripts.  smile


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

Offline

 

#7 2012-01-27 22:01:06

AllButSimilar
New Scratcher
Registered: 2012-01-09
Posts: 20

Re: Continuos Bouncing Off Sprite?

Magnie wrote:

Here is a slightly fixed version of AtomicBawm3's scripts:

DIRECTION

when gf clicked
forever
   move (x) steps
   if <touching [big sprite v]?>
      if <([abs v] of (x position)) > (200)>
         point in direction (<direction> * (-1))
      else
         point in direction (<<<direction> - (90)> * (-1)> + (90))
      end
   end
end
X, Y VELOCITIES

when gf clicked
forever
   change x by (x velocity)
   change y by (y velocity)
   if <touching [big sprite v]?>
      if <([abs v] of (x position)) > (200)>
         set [x velocity] to <(x velocity) * (-1)>
      else
          set [y velocity] to <(y velocity) * (-1)>
      end
   end
end

Thanks!

Offline

 

#8 2012-04-15 11:17:38

UltraScratcher1
Scratcher
Registered: 2012-03-27
Posts: 39

Re: Continuos Bouncing Off Sprite?

AllButSimilar wrote:

I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?

Try this script:

when gf clicked
forever if <touching big sprite>
point in direction <pick random (0) to (360)>
end
smile


|>>>>Risen From The Dead<<<<|

Offline

 

#9 2012-04-15 16:59:11

aryabtsev
Scratcher
Registered: 2012-02-05
Posts: 81

Re: Continuos Bouncing Off Sprite?

UltraScratcher1 wrote:

AllButSimilar wrote:

I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?

Try this script:

when gf clicked
forever if <touching big sprite>
point in direction <pick random (0) to (360)>
end
smile

Well, first, you would have to add a move block and second, random direction means it can continue moving into the big sprite.


http://i.imgur.com/NX7AO.jpg

Offline

 

#10 2012-06-20 09:55:29

chongyian
Scratcher
Registered: 2012-05-08
Posts: 1000+

Re: Continuos Bouncing Off Sprite?

UltraScratcher1 wrote:

AllButSimilar wrote:

I really didn't think this would be hard but someone please help. I have a ball that I'd like to bounce as if it were in a pong game. The only difference, instead of bouncing of the edges it's bouncing off this big sprite surrounding the outside of the project. Help please?
Try this script:

when  clickedforever if touching big spritepoint in direction pick random 0 to 360

Well, first, you would have to add a move block and second, random direction means it can continue moving into the big sprite.


Well, I don't think it works

Offline

 

#11 2012-06-20 09:58:56

chongyian
Scratcher
Registered: 2012-05-08
Posts: 1000+

Re: Continuos Bouncing Off Sprite?

Refer to Pong 4 sided extreme http://scratch.mit.edu/projects/chongyian/2536065

Offline

 

Board footer