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

#1 2012-08-11 06:20:41

arthurz
Scratcher
Registered: 2010-02-03
Posts: 47

SCRIPT DOCTOR NEEDED - make sprite turn the closest way away from edge

Hello fellow scratchers, I ask for help to fix a script

I need help to make an algorithm which will make a sprite turn the closest way away from the edge so if the sprite was near the top edge and its was going diagonal at the angle of this / then it would turn right and vice versa. This needs to happen to all of the side of the edge.

The current code is in this project - http://www.scratch.mit.edu/projects/arthurz/2700286
I have labelled the neccersary code and is explained. its in the ant sprite

Thanks for anyhelp  smile )))


Sine wave engine, check it out.
http://www.scratch.mit.edu/projects/arthurz/2816216

Offline

 

#2 2012-08-11 08:22:54

BirdByte
Scratcher
Registered: 2012-07-07
Posts: 1000+

Re: SCRIPT DOCTOR NEEDED - make sprite turn the closest way away from edge

You're probably thinking about bouncing. Add this:

when gf clicked
forever
 if touching edge, bounce
end


http://i50.tinypic.com/312u714.jpg

Offline

 

#3 2012-08-11 08:45:38

arthurz
Scratcher
Registered: 2010-02-03
Posts: 47

Re: SCRIPT DOCTOR NEEDED - make sprite turn the closest way away from edge

I want the turning motion to be smooth but that has given me a idea if I was to calculate the 'bounced angle' then I can make it turn towards that! This thread is solved


Sine wave engine, check it out.
http://www.scratch.mit.edu/projects/arthurz/2816216

Offline

 

Board footer