Feedback on 2D Planet Jumping Game (C#)?

So I’m very much new to Unity, having just started three days ago, and I have a game that I’m in the midst of working on that I could really use some advice:

I have a character that I want to jump from planet to planet, with the character basically rotating clockwise around the planet while the right arrow key is held and counter clockwise with left.

As of now, I’m still in the midst of ironing out basic syntax errors (I haven’t really coded in a long time) but at the moment, it my thought process is as follows:

  • Character has both a rigidbody and a box collider, while planets have two circle colliders; one on the planet, and the other that’s a trigger which serves as a planet’s atmosphere.

  • With each frame, I want to calculate the distance from the center of the planet to my character, and depending on whether I move right or left, calculate the perpendicular vector at which I should addForce to my character. During all of this, there is a gravitational constant pointing from the character down to the planet’s center that drags him back to the center.

  • To get from planet to planet, my thought process was to have the character jump high/ close enough to touch the atmosphere of another planet. Upon doing so, rotate the figure 180 degrees and pull him onto the surface of the next planet. Repeat as many times as necessary.

As of now, haven’t quite figured out how to rotate the character as he moves around each planet, but does this seem like the right idea so far? I’ve looked into a couple of examples online, and it seems like a lot of examples that involve using a faux gravity also created a rigidbody2D on each planet. I don’t fully understand why this is the case though, since planets would be static gameObjects in this case, and should only have colliders? Is it also necessary to include a Linecast with this sort of problem? Since you’d have to implement a faux gravity here, it doesn’t exactly seem applicable…

Again, sorry for the lack of code and all of the text. Any sort of advice or comments are greatly appreciated!

You seem to be on the right track. You’re right, there would be no reason for the planets to have rigidbodies if they’re static, and I don’t see a reason for raycasting/linecast in your project from the way you describe what the end result should look like.

So what I would is for faux Gravity:
Find vector between character and center of planet (center position - player position) and
RigidyBody2D.AddForce in direction of that vector.

To rotate:
Quaternion.LookRotation to rotate player to center of planet.

To move:
RigidyBody2D.AddForce or RigidyBody2D.MovePosition using player’s local axis ie. Transform.right or Transform.forwards

I am currently working on a Asset Store Package which will do it.