The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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 moveandcollide and moveandslide 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)
Godot version 3.2.3.stable.official
in Engine by (15 points)

1 Answer

+1 vote
Best answer

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.

by (1,514 points)
selected by
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.