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

#1 2009-08-18 14:38:18

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Can you make a sprite circle around point (0,0) ?

I drew a circle, radius 100 and centered at (0,0) and would like to have a sprite keep circling the circumference of my circle. With calculations rounded to two decimal points I was able to do it using a combination of the "turn 0.58 degrees" and "take 1 step" but over time I'm sure the moon's orbit would gradually shift. Is there a way to make a *formula* control the motion?  The formula might be x^2 + y^2 = 10,000, but how do you make it *control* the movement? If it's possible at all, I'd appreciate advice!  :-)

Offline

 

#2 2009-08-18 15:34:05

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Can you make a sprite circle around point (0,0) ?

This project seems to have what you are looking for.
http://scratch.mit.edu/projects/archmage/52542

Just get rid of the jump feature in the cat and make it so that you don't have to press an arrow key to move.

The script to make it rotate around whatever it is pointing at is

forever{
point to (target)
change x by (sin of (direction-90))
change y by (cos of (direction-90))
}

Also remember, scratch isn't too accurate so even with the proper formulas it may mess up.

Last edited by archmage (2009-08-18 15:51:58)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#3 2009-08-18 17:31:57

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: Can you make a sprite circle around point (0,0) ?

Your script works fine! And your "Ruler of the world" project is amazing. You mentioned that the Scratch math might not be totally accurate and, sure enough, I noticed that the Moon circling my Planet gradually spiraled farther out.  But it seems much better to use a formula to control motion like this than the "move" strategy I'd pieced together. Thanks so much for your help. I would never have been able to use trig functions to do anything.

Offline

 

#4 2009-08-18 19:16:45

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Can you make a sprite circle around point (0,0) ?

You could also get rid of all the math and just set the circling sprite's rotation point somewhere outside of its costume (at the distance of the circle's radius), then align the rotation point with the center of your circle and merely "turn" your sprite  smile


Jens Mönig

Offline

 

#5 2009-08-19 19:23:48

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: Can you make a sprite circle around point (0,0) ?

Jens wrote:

You could also get rid of all the math and just set the circling sprite's rotation point somewhere outside of its costume (at the distance of the circle's radius), then align the rotation point with the center of your circle and merely "turn" your sprite  smile

Brilliant, Jens! Thanks. I used the math approach and there was slow deviation. Same with my earlier "move" approach. So now I'll try this.

Offline

 

Board footer