Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 517
Linuxer4Fun Avatar asked Dec 28 '16 15:12

Linuxer4Fun


1 Answers

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

like image 158
nicruo Avatar answered Dec 01 '22 00:12

nicruo