Collision Between Two KinematicBody2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ethanm

In my scene I have two characters using KinematicBody2D for movement that are controlled via user input. The problem is that when the two characters move at each other and collide, instead of stopping they seem to jitter for a few seconds first. I’ve tried using move_and_collide and move_and_slide but neither method seems to change this.
Example GIF

extends KinematicBody2D


export var player = 1
export var walk_speed = 3.0
var velocity = Vector2.ZERO


func _ready():
	#Set up collision layers/masks depending on player 1/2.
	if player == 1:
		self.set_collision_layer_bit(0, true)
		self.set_collision_mask_bit(3, true)
	elif player == 2:
		self.set_collision_layer_bit(3, true)
		self.set_collision_mask_bit(0, true)


func _physics_process(delta):
	#Horizontal Motion
	var input_h = Input.get_action_strength("p%s_right" % player) - Input.get_action_strength("p%s_left" % player)
	velocity.x = input_h * walk_speed
	
	var collision = move_and_collide(velocity * delta)
:bust_in_silhouette: Reply From: Andrea

When 2 kinematic bodies interact this can happen.
Try switching to rigidbody, it has an handy property called mode: you can keep the players in kinematic mode to make them behave as a normal kinematic body, and change them to rigid when a player-player collision is detected.