(godot 4.2.1) how do i make a solar system simulation?
Asked Answered
S

5

0

im planning to remake universe sandbox in godot (in 3d), so, how do i make a solar system simulation?

these are the things i need for the game:

  1. the planets must always orbit the sun, and will drift away when the sun is deleted
  2. all the celestial bodies (the sun, planets, moons, etc) can be draggable and can be thrown
  3. all the celestial bodies can collide with eachother, and when collided, it will launch many other objects
  4. you can add more celestial objects with a ui and a β€œ+” button where you can see celestial objects to add and place them in the simulation, and can make the celestial object orbit the sun, and if placed closely to a planet, it can orbit the said planet
Symmetry answered 5/3 at 19:49 Comment(0)
M
0

Symmetry I'd try to fake the behavior instead of doing an actual physics simulation. I have a saying for stuff like this: "Never use a simulation where you can use an illusion of simulation instead" πŸ™‚

Milurd answered 5/3 at 19:57 Comment(0)
S
0

Milurd oh

Symmetry answered 5/3 at 20:3 Comment(0)
S
0

Milurd could you reply with a code example of a fake simulation but still has the same physics of the things i told in list on the post?

Symmetry answered 5/3 at 23:56 Comment(0)
M
0

I would start with a stationary sun and a single moving planet.

In the planet's _physics_process() method, implement the motion equation to make the planet orbit around the sun. The motion equation should be easy to find on the web, or you could ask ChatGPT.
You could use Sprite2D or Area2D nodes for the sun and the planet. (You said 3D, but I would start with 2D to keep it simple, and change to 3D after you get a simple model working.)

Instead of explicitly specifying the planet's motion, you could try applying a force to a RigidBody2D to simulate the planet's gravitational attraction to the sun. I don't know if Godot's physics is accurate enough, but it shouldn't be hard to test as an experiment.

Symmetry when the sun is deleted

No, don't do that. We need the sun. 😒

Minor answered 6/3 at 0:11 Comment(0)
M
0

Symmetry could you reply with a code example of a fake simulation but still has the same physics of the things i told in list on the post?

There's no such thing as fake simulation. It's either a fake or a simulation πŸ™‚. What I meant was to not use physics equations (or Godot's rigid body facilities) for orbits. It'd be unnecessary and likely unwieldy. Instead, just move the planets/moons uniformly on simple circular paths. Use simulation only for impacts.

With an exact planetary system simulation you also cannot just spawn a planet at random position and let it immediately catch an orbit. It needs initial momentum vector. The whole thing would be rather confusing and unintuitive from player's perspective because they could not predict where the planet/moon would end up orbiting. Especially if it's in 3D.

Since you didn't precisely describe the most important thing - the extents of player interaction - it's hard to give more specific advice.

Milurd answered 6/3 at 1:45 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.