Hello I am currently using a single raycast to check for points in world positions from my player camera. the problem is the min distance between each point can sometimes make the ray misses the corner of the wall which can cause the line to go through the wall. I can make the min distance float very small but it’ll make unnecessary points that will effect performance. I thought since I have the hypotenuse of the corner tringle maybe using it to get the point in the corner but I dont think this is the best way to get it. even if its the best way I dont get how can I add the point in the middle of the list since I already made other points after it I really hope someone can help me with this.
this is my code:
public class Line : MonoBehaviour
{
[SerializeField] private float minDis = 0.1f;
[SerializeField] private List<Vector3> points = new List<Vector3>();
private Camera cam;
private Vector3 lastMousePos;
private void Awake()
{
cam = Camera.main;
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
AddPoint();
}
if(Input.GetMouseButton(0))
{
float dis = Vector3.Distance(GetMousePosition(), lastMousePos);
if (dis > minDis)
{
AddPoint();
}
}
if(Input.GetKeyDown(KeyCode.R))
{
points.Clear();
}
}
private Vector3 GetMousePosition()
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
Physics.Raycast(ray, out RaycastHit hit);
Vector3 vec = hit.point;
return vec;
}
private void AddPoint()
{
if(GetMousePosition() != Vector3.zero)
{
points.Add(GetMousePosition());
lastMousePos = GetMousePosition();
}
}
}