Can any one help with my game

so I have been making a space related game and m trying to figure out how to make the “moon” sprite to orbit the “earth” sprite while also moving with the earth sprite if you move the earth sprite if you want or need to here is my game (it is not done and most of the code is not placed down yet) at the start it is a player select so idk if that will make it harder or not.

Also what should I do for the other charecters

1 Like

You should be able to use Cos and Sin math functions to make the sprite orbit. Cos and Sin take in a variable and output a variable. The input is the rotation in radians, and the output is the x/y position of a point around a circle with radius 1. Cos is x, Sin is y. Basically, you would have a variable like “rotation” and in a forever loop you can set the moon sprite position like

Set moon.x = earth.x + (multiplier • Cos(rotation) )
Set moon.y = earth.y + (multiplier • Sin(rotation) )

The “multiplier” is the distance from the earth you want it to rotate. Since rotation in radians means 360 degrees is the same as 2pi, every frame you should be increasing the rotation variable by a very small amount, like 0.05 or something. That way the orbit is slow.

2 Likes

You could try the sprite utils extension, it allows you to place sprites a distance and angle from another sprite. It can also do a bunch of other stuff. Hope that helps

2 Likes

game with moon code I tried to come up with a solution but It’s kind of choppy and the why I had it before left the moon behind

well that is good for now but now idk what to do with the rest of the characters

I implemented that solution I was talking about. It looks really good. Good luck with the rest of your game!

or what should I do with the game

https://arcade.makecode.com/S79608-29573-59517-79249 here is updated game

1 Like