Small Issue Detecting Collisions with a LineRenderer (2D)

So, I’m trying to detect collision on my laser, and it almost works, but it only covers half of my line.
(ignore the red line)
image
The two dots represent the points I’ve created via script.
image
It is the same thing on the other side.

    private List<Vector2> CalculateColliderPoints()
    {
        Vector3[] positions = GetPositions();
        float width = HitLine.GetComponent<LineRenderer>().startWidth;
        float m = (positions[1].y-positions[0].y)/(positions[1].x-positions[0].x);
        float deltaX = (width/2f)*(m/Mathf.Pow(m*m+1,.5f));
        float deltaY = (width/2)*(1/Mathf.Pow(1+m*m,.5f));
        Vector3[] offsets = new Vector3[2];
        offsets[0]= new Vector3(-deltaX,deltaY);
        offsets[0]= new Vector3(deltaX,-deltaY);
        List<Vector2> colliderPositions = new List<Vector2>{
            positions[0]+offsets[0],
            positions[1]+offsets[0],
            positions[1]+offsets[1],
            positions[0]+offsets[1]
        };
        return colliderPositions;
    }
    private void OnDrawGizmos() {
        Gizmos.color = UnityEngine.Color.magenta;
        if (ColliderPoints!=null) ColliderPoints.ForEach(p=>Gizmos.DrawSphere(p,.1f));
    }
    private Vector3[] GetPositions()
    {
        Vector3[] positions = new Vector3[HitLine.GetComponent<LineRenderer>().positionCount];
        HitLine.GetComponent<LineRenderer>().GetPositions(positions);
        return positions;
    }

This the main code, and then it applies the positions here,

    private void FixedUpdate() {
        if (IsFiring&&HitLine.GetComponent<LineRenderer>().startWidth>=.85f) // the second part is to see if the laser is in fire mode
        {
            ColliderPoints = CalculateColliderPoints();
        }
    }

its also worth mentioning the beam changes sizes, bt even when it is smaller it fails to get the true corner,
giff

If anybody has any tips or experience with this please help me out, I’m not good with this kind of stuff, Thank you.

You can do a CircleCast to detect the beam collisions.

But the beam is a rectangle?

The method casts a circle along a path so it can act like a thick raycast. It’s true that the end of the beam will be circular but nobody will ever know. Or you could use a BoxCast if you think the circle cast could be a problem. Although with the box cast it can be a little more fiddly to use because you have to pass an angle parameter.

But I feel like my code here is almost complete, just a small bit which I can’t seem to figure out, I’ll look into the circle cast though, thank you for the help

i put
offset[0] instead of offset[1]
:confused: