hey, so i have a project where something when collides with a line renderer it dies but this line renderer is always moving/updating so i cant have an collider on it. So i want to know if there is a way to check it without a collider
I can see two (tree actually) ways to solve this:
-
attach some collider to the line gameobject.
-
which is I prefer, use
Physics.Raycast
orPhysics.Linecast
. Ray is more suitable when you know the direction but don’t know what a length the line will be. so you set the direction and max distance. The Line option is if your line has fixed length.Vector3 origin;
Vector3 direction; // or Vector3 endPosition; and then get direction with direction = endPosition - origin
float maxLineLength;
int layerOfKillableObjects // or you can use Physics.AllLLayers so ray will trigger when intersect with any objects
void Update ()
{
RaycastHitInfo hitInfo;
if (Physics.Raycast (origin, direction, out hitInfo, maxLineLength, layerOfKillableObjects, QueryTriggerInteraction.Ignore)
{
Transform deadMan = hitInfo.transform;
// kill that man
}
}