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

#1 2012-10-18 06:05:42

naiad_diana
New Scratcher
Registered: 2012-10-17
Posts: 7

Script for "repel" action

I've been trying to figure this out for hours.
Do you have a script to "repel"? When two sprites bump, they move to the other direction.

Offline

 

#2 2012-10-18 08:02:41

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Script for "repel" action

It depends on how they move. If you only use the [move (10) steps] block and directions to move your sprites, there's an easy way. Otherwise you need some harder math.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#3 2012-10-18 08:10:15

meew0
Scratcher
Registered: 2010-02-22
Posts: 1000+

Re: Script for "repel" action

You could do this:

when gf clicked
forever if <touching [Sprite2 v]?>
move [-10] steps
end

Last edited by meew0 (2012-10-18 08:10:39)


http://i.imgur.com/mJV3j.pnghttp://i.imgur.com/HwWAX.pnghttp://i.imgur.com/sZ7Ui.pnghttp://i.imgur.com/0y6yh.pnghttp://i.imgur.com/nOC4l.png

Offline

 

#4 2012-10-18 08:32:45

naiad_diana
New Scratcher
Registered: 2012-10-17
Posts: 7

Re: Script for "repel" action

I want my sprites to move in random direction when they touch as long as that direction is away from the other. Do you know an easier way to do that?

Offline

 

#5 2012-10-18 08:53:31

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Script for "repel" action

Sure!

when gf clicked
forever
wait until <touching [sprite 2 v]?>
turn ccw ((pick random (0) to (180)) * (pick random (1) to (2))) degrees
move (10) steps

Last edited by Hardmath123 (2012-10-18 08:55:28)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#6 2012-10-18 08:53:48

Willpower
Scratcher
Registered: 2012-01-26
Posts: 1000+

Re: Script for "repel" action

I fail at scratchblocks  sad

This would repel them in a random direction away from the sprite

when gf clicked
forever if <touching [Sprite2 v]?>
point in direction ([180] - (direction))
move [-10] steps
end
Fixed on my post- thanks DVD!

Last edited by Willpower (2012-10-18 11:01:24)


http://i49.tinypic.com/e84kdj.png

Offline

 

#7 2012-10-18 09:06:38

naiad_diana
New Scratcher
Registered: 2012-10-17
Posts: 7

Re: Script for "repel" action

Thank you for the help. I will try feedback tomorrow. It's evening here.

Offline

 

#8 2012-10-18 09:16:59

dvd4
Scratcher
Registered: 2010-06-30
Posts: 1000+

Re: Script for "repel" action

Willpower wrote:

I fail at scratchblocks  sad

This would repel them in a random direction away from the sprite

when gf clicked
forever if <touching [Sprite2 v]?>
point in direction ([180] - (direction))
move [-10] steps
end

fixed


I made a mod  big_smile  It's called blook!
http://i49.tinypic.com/16ia63p.png

Offline

 

#9 2012-10-18 15:21:52

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Script for "repel" action

dvd4 wrote:

Willpower wrote:

I fail at scratchblocks  sad

This would repel them in a random direction away from the sprite

when gf clicked
forever if <touching [Sprite2 v]?>
point in direction ((180) - (direction))
move (-10) steps

fixed

I fixed it even more.


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer