Make GameObject Not pass Through Collisions

Hi so I’m not totally sure how to put this but basically I have a game where I can activate a line that can rotate around my character and allows him to teleport to places. The thing is the line can go through game objects or colliders and still teleport through them. If there is a way to make it so while the line is touching a collider or whatever it cuts off the part that would extend beyond the collider so it looks like its just cutting part of my line off. I was thinking possibly a raycast to check if there are colliders but I’m not totally sure how to implement one. Sorry if this is kind of confusing but I would love some help or I can clarify more if needed.

_
So the most basic method would be to raycast up to x units forward and see if you hit anything.

using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    void FixedUpdate()
    {
        Vector3 fwd = transform.TransformDirection(Vector3.forward);

        if (Physics.Raycast(transform.position, fwd, 10))
            print("There is something in front of the object!");
    }
}

Or raycast until you hit something if you don’t care about distance.

using UnityEngine;

public class RaycastExample : MonoBehaviour
{
    void FixedUpdate()
    {
        RaycastHit hit;
        Vector3 fwd = transform.TransformDirection(Vector3.forward);

        if (Physics.Raycast(transform.position, fwd, out hit))
            print("Found an object - distance: " + hit.distance);
    }
}

You can use out to retrieve information about what the raycast hit and get the transform that could be used as co-ordinates to teleport the player.

As for showing some kind of laser/line in game you could just create a line renderer that starts from the player and ends at the hit point for the raycast.

_

You can also use Debug.DrawRay to view it in the scene window.