HRRV
1
Hi,
I have this little issue with Raycast, I want it to point to a custom Vector3, but it is not working correctly. It keeps pointing to the nowhere. Here is my code:
var tr : Transform;
var mask : LayerMask;
var rayHit : RaycastHit;
var aimAt : Vector3;
function Start () {
tr = transform;
aimAt = Vector3 (0.2, 1.5, 65);
}
function Update () {
if (Physics.Raycast (tr.position, aimAt, rayHit, Mathf.Infinity, mask)) {
Debug.DrawLine (tr.position, rayHit.point, Color.blue);
}
}
If I use “tr.forward” insetead of “aimAt” it works fine pointing to the front:
if (Physics.Raycast (tr.position, tr.forward, rayHit, Mathf.Infinity, mask))
Anyone knows why this is happening?
For Raycast, you give it a position and a direction. You’re giving it a position and another position right? Just do a subtraction, aimAt - tr.position. Or you can use linecast.