Linuxer4Fun
Linuxer4Fun

Reputation: 85

Godot engine collision with KinematicBody doesn't work

I was fiddling around with the Godot engine and tried a little game.

But I can't seem to get an info on colliding.

if is_colliding():
    print ("Collision with " + get_collider())
    get_node("Sprite").set_texture(walk_cycle_right_1)
    move_state_right = 1
    set_pos(Vector2(get_pos().x -10, get_pos().y))

It always prints false. I'm moving my character (KinematicBody2d -> Sprite/CollisionShape2d) with the set_pos command.

Upvotes: 6

Views: 4818

Answers (1)

nicruo
nicruo

Reputation: 516

For the kinematicbody you need to use move or move_to to trigger the collision. If you really need to use set_pos, check collisionshape2d.shape and do the collision check yourself.

There is an example on Godot documentation where KinematicBody2D movement and collisiong handling is introduced: http://docs.godotengine.org/en/stable/tutorials/2d/kinematic_character_2d.html

Full definition for KinematicBody2D class is available also at Godot Documentation: http://docs.godotengine.org/en/stable/classes/class_kinematicbody2d.html?highlight=KinematicBody2D

Upvotes: 2

Related Questions