- Home /
LookRotation and Raycasting
I'm trying to get a raycast to raycast in the direction of a certain object. This is how I attempted to do it:
Vector3 relativePos = objT.transform.position - plane.position;
Quaternion rot = Quaternion.LookRotation(relativePos);
float distance = Vector3.Distance(plane.position, objT.transform.position);
Physics.Raycast(plane.position, rot, out hit, distance);
But I get this error that makes no sense to me:
The best overloaded match for 'UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3, float, int)' has some invalid arguments.
Which makes no sense because the second part is a quaternion, not a Vector3. Anything I'm doing wrong, and is there another better way to do what I'm trying to do? If there is, please explain but still explain to me what I did wrong here. If there isn't....well then just answer the question. Thanks in advance.
Answer by DayyanSisson · Jun 23, 2012 at 10:05 PM
Oh never mind, I figured out what I did wrong. The second argument is supposed to be a Vector3. The code should look like this:
Vector3 rot = objT.transform.position - plane.position;
float distance = Vector3.Distance(plane.position, objT.transform.position);
Physics.Raycast(plane.position, rot, out hit, distance);
Answer by JohnD2012 · Jun 23, 2012 at 10:04 PM
The best overloaded match for 'UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3, float, int)' has some invalid arguments.
Try using a diferrent overload, if you're on mondevelop, use arrowkeys to select different overloads, and then use one that accepts your data..,. thats what i do on overload errors.
I found the answer to my question, but thats actually good to know, thanks.