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():
    animationPlay.play("start_pos")
    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
            animationState.travel("Run")
            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
            else:
                sprite.flip_h = true


        else: 
            velocity.x /= 1.2
            velocity.y /= 1.2
            animationState.travel("Idle")
            speed = 0 


        move_and_slide(velocity)
        print(velocity)

    else:
        velocity = Vector2.ZERO
        input_vec = Vector2.ZERO
        speed = 0
        move_and_slide(cutscene_vec)
Godot version 3.3.2 (stable)
in Engine by (24 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.