Get to the node the player is colliding with

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By szaross

Hi. How can I get to the node the player is colliding with?
This node is in another scene but I dont think it will make any difference.
(by get to the node I mean smth like get_node). The body I am colliding with is Area2D.

What type of node is your player body?

Zylann | 2019-06-19 12:41

KinematicBody

szaross | 2019-06-19 12:52

:bust_in_silhouette: Reply From: Zylann

If you move your player with move_and_collide, it returns colliding bodies in its return value: KinematicBody2D — Godot Engine (3.1) documentation in English

An alternate way is to detect collisions the other way around, from your area instead by using body_entered signal.

Both solution don’t require you to use get_node because they provide the body node directly.

More info here: Using KinematicBody2D — Godot Engine (3.1) documentation in English

oh didint know that. thanks!

szaross | 2019-06-19 13:33