Ray Casts not working and sometimes casting in the wrong direction, help!
I have recently had the issue where raycasts will not work no matter what I do. (The code)
public class Joe : MonoBehaviour // Doesn't Include Usings for this post as it's just clutter
{
public Transform point1;
public Transform point2;
// Update is called once per frame
void Update()
{
if (Physics.Raycast(point1.position, point2.position))
{
Debug.DrawRay(point1.position, point2.position);
}
if (Physics.Raycast(point1.position, point1.forward))
{
Debug.DrawRay(point1.position, point1.forward);
}
}
}
What the Ray Casts actually do.
Supposed to be Ray Casting here.
If the two boxes collide it actually shows the Ray Cast but it's going off in a random direction.
![alt text][2]
I have tried this in different projects and scenes to no avail. Please someone provide a fix to this, I'm dying here. [2]: /storage/temp/189633-2.png
if (Physics.Raycast(point1.position, point2.position))
{
Debug.DrawRay(point1.position, point2.position);
}
Does not make sense. Physics.Raycast
& Debug.DrawRay
take a position (origin) and a direction, not two positions. If you want to provide two positions, use Physics.LineCast
& Debug.DrawLine
You actual legend thank you so much! It works like a charm now!
Now there is a different issue, the line cast only works when the object the line is being casted to is behind something else.