Basic question: how to move around a sphere?

Godot Version

4.3.stable

Question

I just kind of dove in, I’m not exactly sure what I’m doing…

So I’m trying to make a 3D game that, to me, sounds pretty simple.

I want to make a game where a little riding mower moves around a sphere to mow the “planet”. I want the forward movement constant and the player only controls the turning of the character.

I have a scene with the mower

  • RigidBody3D
  • CollisionShape3D
  • MeshInstance3D
  • RayCast3D

I have a scene with the planet, similar setup

  • StaticBody3D
  • collision shape
  • mesh instance
    Along with a directional light and a camera, I added the mower scene into this scene.

Does the mower need to be “attached” to the sphere somehow or would I need to code “rotations” when the mower moves around the planet?

I saw in a tutorial that someone in an endless runner tutorial moved the ground instead of the player, that seems like it would be a good fit here, just rotate the sphere and keep the mower in the center.

Does anyone know of a godot project that does something similar? I’m ok with tutorials but I’d like to see an actual project that someone made that I can study and look through. It would be nice to see how other people setup their projects.

You could use apply_force on RigidBody3D to add gravity to it each frame, dependant on the position relative to the planet
To figure out how to give player gravity, planet.global.position - mower.global_position could be used

If we want to position mower that its always in the right rotation, opposite vector could be used to find upward position (mower.global_position - planet.global.position) but that only works if planet is a perfect sphere. If not i bet you could shoot a RayCast along planet.global.position - mower.global_position and check the normal vector of the hit. After that
we would somehow need to transform vector into rotation angles, which i am not sure how to do.

After that moving the mower would probably be as easy as giving it velocity along its forward vector (global_transform.basis * Vector3.FORWARD)

If CharacterBody3D is used for mower instead of RigidBody3D, we could also set up_direction so that mower would know if its colliding with a floor, wall or ceilling.