0 votes

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.

asked Dec 21, 2017 in Engine by PugMasterPug (116 points)

1 Answer

+1 vote

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.

answered Dec 21, 2017 by kidscancode (17,004 points)
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 How to use this Q&A? before posting your first questions.