Compare object and get_collider()

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

I have a raycast2d that I want to detect what it is colliding with then compare it with it statements.
When I print the object it returns [KinematicBody2D:1229].
How would I compare that with get_collider() in an “if” statement?

if raycast.get_collider() == Object:
	print("hit")
else:
	print("no hit")

This is what I have so far.

:bust_in_silhouette: Reply From: exuin

You also need a reference to the object you want to compare the collider to. Like, if you have

var player = $Player

You would do

if raycast.get_collider() == player:

Thank you! Applied this and it worked like I wanted to.

15erixman | 2021-09-14 16:58