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

#1 2012-08-29 15:38:51

princes1234
Scratcher
Registered: 2012-08-28
Posts: 1

how to move a sprite randomly

hello im good with scratch but i wanna know how to move a player radomely but when touching a certain colour it turns cuz im making a game and theres a brown fence so i need it to bounce back when touching coour brown thanks

from princes1234

Offline

 

#2 2012-08-29 16:00:14

777w
Scratcher
Registered: 2009-02-10
Posts: 1000+

Re: how to move a sprite randomly

if you want the player to bounce back then you dont want them to move randomly but if you want them to move randomly try this:

if <touching colour []>
  change x by (pick random (-3) to (3))
  change y by (pick random (-3) to (3))

Offline

 

#3 2012-08-29 16:00:48

benjamin2
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: how to move a sprite randomly

It requires very advanced trigonometry to detect the trajectory of the wall.


http://i.imgur.com/gp6tZ.gif

Offline

 

#4 2012-08-29 17:27:21

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

Re: how to move a sprite randomly

benjamin2 wrote:

It requires very advanced trigonometry to detect the trajectory of the wall.

Not really, assuming its only horizontal, vertical or 45 125 etc degrees. you just need a sensor

forever
if <touching color (brown)?>
if <color (left colour) is touching (brown)?>
change x by (5)
and you do that for the other colours

Last edited by zammer990 (2012-08-29 17:29:43)


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

Offline

 

#5 2012-08-30 00:17:29

roars1111
New Scratcher
Registered: 2012-08-30
Posts: 5

Re: how to move a sprite randomly

You can supply your own modifier finished listener to the path modifier, when the method is called you can create and add a new path modifier to your sprite.

It's really inefficient though as you have to create a new Path object and a new Path Modifier object each time when all you're doing is changing some values.

If you find that you're using too much memory its worth rewriting, or at least adding to those classes to allow them to be updated rather than recreated.

Offline

 

#6 2012-08-30 01:03:59

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: how to move a sprite randomly

^^ Unfortunately, Scratch doesn't support object-oriented programming.

Offline

 

Board footer