0 votes

I have a KinematicBody2D colliding with a StaticBody2D. The KinematicBody2D is to find out the name of the StaticBody2D. It's simple, but I did not find out. I look forward to any help.

in Engine by (73 points)
recategorized by

Some more information would be helpful:

Are you using Godot 2.1 or 3.0?

move_and_collide() or move_and_slide()?

I use Godot 2.1
I need move_and_collide() and move_and_slide()

Well, move_and_collide() doesn't exist in 2.1, it's a 3.0 function. In 2.1 you'd use move(), so I'll answer assuming that's what you're using.

1 Answer

+1 vote
Best answer

KinematicBody2D detects collisions when moving, so here's an example using the move() function:

func _fixed_process(delta):
    move(velocity * delta)
    if is_colliding():
        print(get_collider().get_name())
by (22,069 points)
selected by

I found my problem. I wrote the script before themove() methods. I also needed the Is_move_and_slide_on_floor() method.

if is_move_and_slide_on_floor():
    var collide = get_move_and_slide_colliders()
    for body in collide:
        if body.get_name() == "Exit":
            get_node("/root/Square_Game").queue_free()
            get_tree().change_scene("res://Level_select.tscn")
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.