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.
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);
Have you tried just setting the y to 0f?
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
3 days ago
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.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
357 People are following this question.
How do I check if a GameObject is within or colliding with an arc?
Raycast does not seem to properly detect object it hit
How to Destroy game object horizontally and vertically , when hit by a Raycast
Raycast doesn't stay in one place