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

#1 2013-03-18 21:23:02

SVA_JSanderson
New Scratcher
Registered: 2013-03-18
Posts: 2

Traveling in circles and semi-circles

I am recreating galaga and have my sprites traveling down from the top then in a half circle and back up, much like a U shape. My code is just a serious of glides to various points I plotted. I would like to clean up my code and not have to plot points in order to make it perform a circle. I have found equations for a circle but I am not able to make it work for my specific project. Any help would be useful thanks.

Offline

 

#2 2013-03-19 03:51:12

shadowmouse
New Scratcher
Registered: 2013-02-03
Posts: 100+

Re: Traveling in circles and semi-circles

Why not do something like:
when gf clicked
go to start position
forever
point in diretion 180
repeat 100
move 1 steps
end
repeat 180
turn 1 clockwise
move 1 steps
end
repeat 100
move 1 steps
end
glide to start position

Offline

 

#3 2013-03-19 06:19:33

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Traveling in circles and semi-circles

You can use trigonometry to accurately position a sprite on a circle.  Use equations like this:

Set angle to 0
Repeat 360
    Set sprite X to XC + R*sin(angle)
    Set sprite Y to YC + R*cos(angle)
    change angle by 1

XC and YC are the center of the circle, R is the radius.  You can change the speed that the sprite goes along the circular path by changing how fast the angle changes.  Hope that helps  smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#4 2013-03-19 16:29:01

SVA_JSanderson
New Scratcher
Registered: 2013-03-18
Posts: 2

Re: Traveling in circles and semi-circles

Thanks, I will try them and see how it works

Offline

 

Board footer