Godot engine collision with KinematicBody doesn't work
Asked Answered
M

1

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.

Monoxide answered 28/12, 2016 at 15:38 Comment(0)
C
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

Carothers answered 4/1, 2017 at 10:45 Comment(4)
Ok. Thank you ;-)Monoxide
I used set_pos to make the Blaster go in 360 Directions. But how can I achieve this with move()?Monoxide
@Monoxide You should accept the answer and ask another question. Do not ask different questions in comments.Imbrue
@sm4 ok. Sorry.Monoxide

© 2022 - 2024 — McMap. All rights reserved.