I'm having a really weird issue. I've been working on basic movement code for a JRPG recently; it works for the most part, but I'm having issues with collision. While it works smoothly normally, when the player runs into a wall, their sprite starts to jitter. For some reason, this only happens with colliding with something.
The player is a KinematicBody2D. Here's the movement script I'm using:
func _physics_process(delta):
var direction = Vector2.ZERO
if Input.is_action_pressed("stick_right"):
direction.x += 1
dir = 2
if Input.is_action_pressed("stick_left"):
direction.x -= 1
dir = 1
if Input.is_action_pressed("stick_down"):
direction.y += 1
diry = 2
if Input.is_action_pressed("stick_up"):
direction.y -= 1
diry = 1
if Input.is_action_pressed("button_x"):
speed = runspeed
else:
speed = walkspeed
direction = direction.normalized()
direction *= speed
if direction != Vector2.ZERO:
if dir == 1:
animate("walk_l")
elif dir == 2:
animate("walk_r")
$Player.move_and_collide(direction)
else:
if dir == 1:
animate("stand_l")
elif dir == 2:
animate("stand_r")