0 votes

My KinematicBody2D works fine when moving left, right, up, and down, but if I move him at an angle his sprite shakes, and jitters violently, and I'm not sure what to do about it...

My code:

  extends KinematicBody2D

var input_vec = Vector2.ZERO
var velocity = Vector2.ZERO
var cutscene_vec = Vector2.ZERO
var speed = 0
var room = 1
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")
onready var animationPlay = $AnimationPlayer
onready var loop_timer = $loop_timer
const accel = 4 
var boost = 0
onready var sprite = $Sprite

func _ready():
    animationTree.active = true

func _physics_process(delta):
    if GlobalVars.move == 1:
        input_vec.x = Input.get_action_strength("right") - Input.get_action_strength("left")
        input_vec.y = Input.get_action_strength("down") - Input.get_action_strength("up")
        input_vec = input_vec.normalized()

        if input_vec != Vector2.ZERO:
            velocity.x = input_vec.x * speed
            velocity.y = input_vec.y * speed
            animationTree.set("parameters/Idle/blend_position", input_vec)
            animationTree.set("parameters/Run/blend_position", input_vec)

            if speed < 60:
                speed += accel

            if velocity.x > 0:
                sprite.flip_h = false
                sprite.flip_h = true

            velocity.x /= 1.2
            velocity.y /= 1.2
            speed = 0 


        velocity = Vector2.ZERO
        input_vec = Vector2.ZERO
        speed = 0
Godot version 3.3.2 (stable)
in Engine by (40 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 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 webmaster@godotengine.org with your username.