0 votes

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)
Godot version v3.4.stable.official [206ba70f4]
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.