How to change direction of gravity?

Godot Version

4.6

Question

I want to make a game very similar to super monkey ball. This would be done by changing the angle that a sphere is affected by gravity. I do not want to just reverse gravity, I want to make it so that when I press 'Up', the gravity of the ball is changed so that it rolls forward, and when I press 'Left', the ball rolls left, in a circle. This is a big ask, but I don't know where I would even start

Are you sure you want to change gravity? From your description it sounds like you need a RigidBody3D and apply_central_force().

If you don’t know how to do it, I’d suggest you to start with this tutorial series:

Think how gravity works on the engine gravity is a force you apply in your controller. So, you can, instead to add an scalar affecting the Y axis, you can use a Vector3 and add it in a similar way.

By doing this, your gravity can be applied on ANY direction.

You can define Vector3 as direction and a gravity force which multiplied by its direction will affect the movement.

As an example, a simple controller will:

if not is_on_floor():
		velocity.y -= gravity * delta

You could:

if not is_on_floor(): # or wall or any collision you choose
		velocity -= gravity * gravity_direction * delta