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
Mar 21 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.
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
356 People are following this question.
Raycast does not seem to properly detect object it hit
error CS0117: `UnityEngine.Physics' does not contain a definition for `RayCast'
How to Destroy game object horizontally and vertically , when hit by a Raycast
Raycast doesn't stay in one place