I’ve been messing around drawing lines in circles and checking if they collide with things and ran into a problem, i feel like i’m missing something, I can draw lines just fine with line renderer, but when make a ray, the further from the global origin i set the ray origin the more it appears to be rotating around the origin. the red lines are rays and the white lines are rendered lines:

using System.Collections.Generic;
using UnityEngine;
public class raycheck : MonoBehaviour
{
private Vector2 _origin;
private Vector2 _circumfrance;
public float radius = 8;
public int lines = 360;
private int linenumber;
private float _degrees;
public Material spriteMaterial;
private List<GameObject> listOfLines;
public Color outerColor;
public Color innerColor;
// Use this for initialization
void Start()
{
_origin = transform.position;
_degrees = 360 / (float)lines;
linenumber = 1;
listOfLines = new List<GameObject>();
CreateCircle();
}
// Update is called once per frame
void Update()
{
if (!Vector2.Equals(_origin, transform.position))
{
DestroyCircle();
//transform.position = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition);
_origin = transform.position;
CreateCircle();
}
}
void CreateCircle()
{
for (int i = 0; i < lines; i++)
{
DrawLine(transform.position, radius, innerColor, outerColor);
}
}
void DestroyCircle()
{
foreach(GameObject line in listOfLines)
{
Destroy(line);
}
listOfLines.Clear();
linenumber = 1;
}
void DrawLine(Vector2 startingPoint, float vertexRadius, Color startColor, Color endColor)
{
GameObject obj = new GameObject();
obj.name = "Line " + linenumber;
listOfLines.Add(obj);
LineRenderer line = obj.AddComponent<LineRenderer>();
line.material = spriteMaterial;
line.enabled = true;
line.sortingLayerName = "UI";
line.sortingOrder = 0;
line.positionCount = 2;
line.SetPosition(0, startingPoint);
//float sidelength = 2 * vertexRadius * Mathf.Sin((180 / (float)lines) * Mathf.Deg2Rad);
//float apothem = sidelength / (2 * Mathf.Tan((180 / (float)lines) * Mathf.Deg2Rad));//interchangable
//float apothem = vertexRadius * Mathf.Cos((180 / (float)lines) * Mathf.Deg2Rad); // interchangable
float t_x = startingPoint.x + vertexRadius * Mathf.Sin((_degrees * (linenumber - 1) * Mathf.Deg2Rad));
float t_y = startingPoint.y + vertexRadius * Mathf.Cos((_degrees * (linenumber - 1) * Mathf.Deg2Rad));
Vector2 midpoint = new Vector2(t_x, t_y);
RaycastHit2D hit = Physics2D.Raycast(startingPoint, midpoint);
Debug.DrawRay(startingPoint, midpoint,Color.red);
if (hit)
{
midpoint = hit.point;
}
//else
//{
// Ray2D ray = new Ray2D((Vector3)startingPoint, (Vector3)midpoint);
// midpoint = ray.GetPoint(radius);
//}
line.SetPosition(1, midpoint);
line.startWidth = .05f;
line.endWidth = .05f;
line.useWorldSpace = true;
line.startColor = startColor;
line.endColor = endColor;
linenumber++;
}
}
edit
Switched to line casting and it works as expected, odd, hopefully i’ll find out whay that is eventually.