How could this be happening? I've already rewritten the Raycast code a few times, but here is the current iteration:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RaycastTest : MonoBehaviour {
//width will control the distance of the two rays' direction from each other
//range will control the collision range
public float width, range;
//will take width and control bias in the furture
float b;
void Start()
{
}
void Update () {
//loop from negative one to positive one to add left and right rays in the future
for (int i = -1; i < 3; i += 2)
{
//commented line segment showing how bias will work to control the angle of the ray
//! cant do any of that yet because this ray doesn't work
Ray ray = new Ray(transform.position, /*(transform.forward + transform.right/2 * i) / 3*/ transform.forward);
RaycastHit hitInfo;
if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, range))
{
Debug.DrawLine(ray.origin, hitInfo.point, Color.red);
}
else
{
Debug.DrawLine(ray.origin, ray.direction * range, Color.green);
}
}
}
}
The issue is probably either at line 24 or 27, but I still have no clue how its coming up.
EDIT: I tested this by setting the ray direction to a constant: (-1, 0, 0) (global left) and the issue persisted, so it is probably an issue with the Ray declaration in line 24.