How to make a sprite move in a circle?

Is there a way to move sprites in a circle? A student wants to have his spaceship move around in a circle continuously.

I found this formula online, but it doesn’t seem to work.

x=rcos(theta)
y=r
sin(theta)

Thanks in advance!

Nick

There are two common ways to make a circle. One uses a parametric function, as you described in your post. Theta has to increase by a certain amount each iteration of the draw loop. This might make sense to people who liked their high school math classes, especially trigonometry. :slight_smile:

Another way is think about the sprite moving the way that a person would move in a circle. I have a constant speed, but I change my angle a little bit each time.

This project shows both ways of doing it: Circles

The red ship uses a parametric equation to plot the ship at a particular place on the screen. Notice that sine and cosine take radians for their angle parameters.

The green ship puts the ship somewhere, then sets its speed and direction every time, using the “setSpeedAndDirection” command. The speed is always the same, but the direction changes slightly according to the counter pattern. Notice that this command takes degrees for its angle parameter.

You can also use “rotateToDirection” to make the sprite point in the direction it is moving. That only works for the “setSpeedAndDirection” because when you use a parametric equation, you’re not actually giving it direction, just plotting it in a particular place every time.

Elizabeth

3 Likes