How to detect object along line?

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

I need an object to be able to detect when an object is along a certain line, and it must be able to detect the group of the object (I want a spike that falls when the player crosses that line), I tries with a RayCast2D, but it only detects the object when it is at the end of the line.
btw it is a 2D game.

:bust_in_silhouette: Reply From: kidscancode

A RayCast2D doesn’t only detect contact at the end of the line. It extends from a point a certain distance (cast_to) and reports the first collision it detects along that line. This should work fine for your purposes.

Alternatively, give the spike an Area2D and use a LineShape2D as its shape. Then you can use the body_entered() signal to notify you when the player touches the line.