Hi there,
I’m messing around with Unity as a beginner, waiting primarily for my new laptop to arrive (3 days!), and I ran into a problem.
I’m trying to instantiate objects (simple cube at the moment) at a point where I click with my mouse. I was reading through some docs, when I came across these pages;
The first one uses Input.Mouseposition as a Vector3 variable in Camera.ScreenPointToRay, which seems odd to me.
Regardless, I’ve tried messing around with Debug.DrawLine and such, and ended up logging the RaycastHit.point value. Which is always at 0,0,0. To my knowledge it’s supposed to return the world space coordinates of the ray’s hit.
I’m currently using this script;
var particle : GameObject;
var debugraystart : Vector3;
var debugrayend : Vector3;
function Update ()
{
if (Input.GetButtonDown ("Fire1"))
{
var ray = Camera.main.ScreenPointToRay (Input.mousePosition); // Construct a ray from the current mouse coordinates
var hit : RaycastHit;
if (Physics.Raycast (ray))
{
Debug.DrawLine (hit.point, debugrayend, Color.red);
Debug.Log(hit.point);
//Instantiate (particle, hit.point, transform.rotation); // Create a particle if hit
}
}
}
I changed alot over time, mainly to try and get the position to work.
Can anyone give me an explanation as to why RaycastHit.point always returns 0,0,0?