So, I have this.
private void getInputData()
{
//gets the mouse click position and places a unit at that location.
RaycastHit hit;
Ray ray = playerCam.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast (ray ,out hit, 1000))
{
Debug.Log(hit.point);
if (hit.collider.gameObject.tag == "Terrain")
{
//Creates a unit if nothing is there.
Debug.Log("I hit the terrain!");
createSelectedUnit (selectedUnit, hit.point);
}
else if (hit.collider.gameObject.tag == "Melee" ||
hit.collider.gameObject.tag == "PlayerHero")
{
//This is a blanket if/then statement for all units that the player can control.
//If player hits the unit, show some info on GUI.
}
else if (hit.collider.gameObject.tag == "Dist_Melee" ||
hit.collider.gameObject.tag == "EnemyHero")
{
//This is a blanket if/then statement for all units that the enemy controls.
//If player hits the unit, show some info on GUI.
}
}
}
So I’m shooting a ray from a camera at a terrain at (value, 0, value) and according to the hit.point debug it’s not hitting the ground half the time. That is, it’s not (value, 0, value) being shown but (value, value, value).
My question is this: What do I do to ensure that the ray being shot from the camera will always hit the ground?
Bonus points if you can shed some light on why the ray from the camera isn’t hitting the ground to begin with.