Kinematic object does not detect any collisions - Godot

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By edimemune
:warning: Old Version Published before Godot 3 was released.

I am learning Godot game engine and I tried to make a ball that can walk and can’t go through other objects, but the ball keep going through the other objects.

Here is the code:

extends KinematicBody2D

export var viteza = 140

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    delta *= 5
    var motion = Vector2()

    if Input.is_key_pressed(KEY_UP):
        motion[0] = 0
        motion[1] = -1

    if Input.is_key_pressed(KEY_DOWN):
        motion[0] = 0
        motion[1] = 1

    if Input.is_key_pressed(KEY_LEFT):
        motion[0] = -1
        motion[1] = 0

    if Input.is_key_pressed(KEY_RIGHT):
        motion[0] = 1
        motion[1] = 0

    motion = motion * viteza * delta
    set_pos(get_pos() + motion)

What is wrong?

:bust_in_silhouette: Reply From: quijipixel

When using the KinematicBody2D node avoid using set_pos to change position. Use move instead. The move method was created with collisions in mind, when the object collides move won’t allow the object to go any further.

Thank you very much. Now it’s working. :slight_smile:

edimemune | 2017-09-06 23:01