Shoot towards mouse except mouse y
I'm building a sort-of Top Down shooter game but with a certain angle. I have a script that lookstowardsmouse but isn't perfect so I'm not using that rotation to raycast. I'm using the mouse to raycast but I want to ignore the Y axis since you don't really need to (or should) be able to shoot up or down. Basically the raycast should cast straight ahead and ignore the mousePosition.y in the game.
RaycastHit hit;
Ray vRay = myCam.ScreenPointToRay(new Vector3(Input.mousePosition.x, IGNOREPOSITION.Y, Input.mousePosition.z));
if (Physics.Raycast(vRay, out hit, range))
{
Debug.Log(hit.transform.name + "found");
GameObject createHole = Instantiate(bulletHole, hit.point, Quaternion.identity);
}
what should the constant height be? if you want it in half of the screen use half the screen height for your y
Answer by JustinEllis · Mar 21, 2017 at 11:39 PM
If you're looking to only have to have two coordinates try using this instead or just set the y position to a constant such as 0.
Ray2D https://docs.unity3d.com/ScriptReference/Ray2D-ctor.html