How can I make a spaceship controller with rigid bodies that doesn't use set_linear_velocity?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CosmicLife

I am making a game about a spaceship and want to use the area 2D gravity to simulate the gravity of planets. This only works with rigidbodies and I really don’t want to code all the physics myself for a kinematic body so I’m using a rigidbody. In order to make the character controller I used set_linear_velocity which is the most stable method I have found. And while it controls well it means that the ship isn’t affected by gravity while you are controlling it. Here is the code

var max_speed = 100
var speed = 10
var rotationSpeed = 2
var acceleration = 2

func _physics_process(delta):
	if Input.is_action_pressed("Left_Click"):
		if speed < max_speed: 
			speed = speed + acceleration
		var velocity = Vector2(speed, 0)
    if speed < max_speed: 
	        speed = speed - 0.5

Please make sure that your solution won’t cause the spaceship to feel too slippery, because while that is realistic it isn’t fun. Some slipperiness is perfectly fine though. Sorry for being so demanding and even a partial solution is ok, I’ve just been having a lot of trouble and found very little about this topic, as rigidbody characters seem to be quite uncommon.

:bust_in_silhouette: Reply From: SteveSmith

Gravity is just the extra force applied that moves an object towards a large mass. Find the direction of this mass (usually downwards) and add this to your setlinearvelocity() call.