Discuss Scratch

Code_Name_Geek
Scratcher
100+ posts

Sprite moving in circle around a central point

Does anyone know how to make a sprite move in a circle around a central point?
Dreamo
Scratcher
500+ posts

Sprite moving in circle around a central point

It's easy. When you go to the costume editor, you will see there is a cross in the middle. That is the central point your sprite will be rotating around. Then, just use this script to move the sprite around that central point:
turndegrees

Hopefully I helped
Alberknyis
Scratcher
1000+ posts

Sprite moving in circle around a central point

Central point will be somewhere on the map.
So it will have the values X,Y.

setCenter xtoInsert number heresetCenter ytoInsert number heresetdistance_toInsert number heredistance from the pointsetturn speedtoInsert number herethe speed it will rotate around the point (in degrees, not pixels)setstarttoInsert number herestarting positionforeverchangestartbyturnspeedgotox:sinofstart*distance_+CenterXy:cosofstart*distance_+Centery

Sorry, I was in a rush. Tell me if there's a problem.
Code_Name_Geek
Scratcher
100+ posts

Sprite moving in circle around a central point

Okay, I understand now. Thanks for the help guys!
Moltastro
Scratcher
5 posts

Sprite moving in circle around a central point

@alberknyis

how are you supposed to write the start position?
awesomeawesxomeman3
Scratcher
62 posts

Sprite moving in circle around a central point

Moltastro wrote:

@alberknyis

how are you supposed to write the start position?

it's not really a start position, but rather a start angle. (note that sine and cosine work through radians, so you should convert degrees to radians when adjusting that number. Example below)

setradianstodegrees*3.14159/180

also, please refrain from bumping old threads

Last edited by awesomeawesxomeman3 (Jan. 1, 2018 21:32:15)

alexgiurumescu
Scratcher
99 posts

Sprite moving in circle around a central point

Alberknyis wrote:

Central point will be somewhere on the map.
So it will have the values X,Y.

setCenter xtoInsert number heresetCenter ytoInsert number heresetdistance_toInsert number heredistance from the pointsetturn speedtoInsert number herethe speed it will rotate around the point (in degrees, not pixels)setstarttoInsert number herestarting positionforeverchangestartbyturnspeedgotox:sinofstart*distance_+CenterXy:cosofstart*distance_+Centery

Sorry, I was in a rush. Tell me if there's a problem.
This script is correct, it is one that is effective because you can change it easily.
BuzzFun
Scratcher
15 posts

Sprite moving in circle around a central point

What if your “central point” is a sprite that moves around?
deck26
Scratcher
1000+ posts

Sprite moving in circle around a central point

BuzzFun wrote:

What if your “central point” is a sprite that moves around?
Makes no difference! Either save the position when you start moving the circling sprite (Center X, Center Y above) or use the current position of the centre sprite in the goto x, y equations.
BuzzFun
Scratcher
15 posts

Sprite moving in circle around a central point

I meant like if you are making a dodgeball game and you want the character to turn around with the ball in its hands, and that character will move around and occasionally need the ball to “circle around” it.
wolfbomb
Scratcher
14 posts

Sprite moving in circle around a central point

BuzzFun wrote:

I meant like if you are making a dodgeball game and you want the character to turn around with the ball in its hands, and that character will move around and occasionally need the ball to “circle around” it.

just set centre X and centre Y to the player's position. You can turn the script into a custom block and then only call it when you need it. Furthermore, if you want the object to revolve around a point at exactly the point it started at, calculate the distance between the points using trig.

Last edited by wolfbomb (Feb. 15, 2022 02:44:32)

alboxer2000
Scratcher
500+ posts

Sprite moving in circle around a central point

There's another way:
repeat360*howmanytimesmove5/10stepsturn10degreessetrotationstyledon't rotate
Or you can replace this block:
repeatnumber
With:
gotox:50y:-50scratchblocksforevermove5/10stepsturn10degreessetrotationstyledon't rotate/scratchblocks...ifyouwanttobespinninginacircleforever.
Sorry for this scratchblocks things…

Last edited by alboxer2000 (April 30, 2022 16:40:10)

alboxer2000
Scratcher
500+ posts

Sprite moving in circle around a central point

Alberknyis wrote:

Central point will be somewhere on the map.
So it will have the values X,Y.

setCenter xtoInsert number heresetCenter ytoInsert number heresetdistance_toInsert number heredistance from the pointsetturn speedtoInsert number herethe speed it will rotate around the point (in degrees, not pixels)setstarttoInsert number herestarting positionforeverchangestartbyturnspeedgotox:sinofstart*distance_+CenterXy:cosofstart*distance_+Centery

Sorry, I was in a rush. Tell me if there's a problem.
there are no problems

Powered by DjangoBB