I've got this simple script for moving around, and jumping on a planet in 2D.
Currently though, when standing still or holding any movement key down for an extended duration the player will spin out of control around the planet. I'm quite new to Godot and I'm stumped by this problem.
Gyazo gif of the problem in action
https://gyazo.com/4cfbb16cc959ad50d8cf5bcde056ffa5
The only script in this scene is on the player (KinematicBody2D):
extends KinematicBody2D
export var move_speed = 200.0
var velocity := Vector2.ZERO
onready var target = get_parent().get_node("Planet")
onready var jump_velocity := -800
onready var jump_gravity := 1600
onready var fall_gravity := 400
func _physics_process(delta):
var gravity_dir = (target.global_transform.origin - global_transform.origin).normalized()
var rotatedVelocity = velocity.rotated(rotation)
var input_vector = Vector2.ZERO
input_vector = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
velocity.y += jump_gravity * delta
velocity.x = input_vector * move_speed
rotation = gravity_dir.angle() - PI/2
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_velocity
rotatedVelocity = move_and_slide(rotatedVelocity, -gravity_dir)