6

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.

Ondrej Slinták
  • 31,386
  • 20
  • 94
  • 126
Linuxer4Fun
  • 85
  • 1
  • 6

1 Answers1

2

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

nicruo
  • 508
  • 4
  • 13