How do I check the object a ray is colliding with?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SupToasty
:warning: Old Version Published before Godot 3 was released.

I want to check my Player node against an enemy that is casting a ray. How would is return my Player to get_collider() as a type Object, or what other methods could I possibly use to test for these kinds of conditions?

:bust_in_silhouette: Reply From: Gokudomatic2

Your question is confusing. Are you asking how to detect when the player enters the raycast? In that case, use the extends condition with the get_collider() and a preload(“player.gd”).

So to tell if my player enters the ray and not another object i would use if (get_collider () extendeds preload("my player's script"))?

SupToasty | 2016-04-21 14:19

I don’t think that would work in one line. You must first store the preload result in a variable. But otherwise, yes, that’s the idea.

Gokudomatic2 | 2016-04-21 14:54

Thanks Gokudomatic2.

SupToasty | 2016-04-21 16:36