The cursor you see on screen is simply showing that vector2 value, it is not informing it. The cursor position is just a simple vector2 variable. You're getting the screen point from a transform there's no transform associated with the cursor position. This comes in very handy for a lot of lays it out pretty well. You can take advantage of all this pre-existing math and create logic that goes back and forth from world to screen at will. Remember that for any 3d image to be displayed on the 2d screen, it first needs to projected into 2d. You can do this by adding another image to your canvas (same place your on-screen joysticks are) and syncing its position to your logical reticle vector2.
#Crosshair overlay fullscreen unity game code
Now that you have a direction, you can simply shoot it! You'd replace ballSpawn.forward in your Player code with that ray.įinally, you probably want some way to represent your shooting direction on the screen. The ray returned from ScreenPointToRay is a normalized version of one of the red arrows. Your reticle point is represented by one of those x's. This is for raytracing, but the concept is the same. Feed it your screen position and it will return a ray that goes from where the camera is, through the point specified on the screen, out into the world. Your camera has a method called ScreenPointToRay, whose purpose is self-explanatory. Next, you need to change that point into a direction to shoot. This value can be modified by your on-screen joystick the same way you're currently rotating your targeting object. You can keep track of this with a simple 2d vector, where the x is the horizontal pixel position and the y is the vertical. This comes in very handy for a lot of lays it out pretty well.įirst, you need a way to keep track of where your cursor is.
![crosshair overlay fullscreen unity game crosshair overlay fullscreen unity game](http://noxaser.weebly.com/uploads/1/3/3/4/133430400/378710037_orig.jpg)
![crosshair overlay fullscreen unity game crosshair overlay fullscreen unity game](https://cdn1.epicgames.com/ue/item/CrosshairPack100_Featured-476x246-5689ef92348729dad9604d90a3b7880a.png)
![crosshair overlay fullscreen unity game crosshair overlay fullscreen unity game](http://www.gearhack.com/Forums/Computer/Games/draw_your_own_crosshair_in_first-person_shooters.files.hidden/Marking%20the%20Crosshair.jpg)
If it helps, here is a video of me demonstration my issue:Ĭlick to expand.That's correct. Honestly, this is just what I came up with, I am willing to scrap my entire targeting system if there is a better way.
![crosshair overlay fullscreen unity game crosshair overlay fullscreen unity game](https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/1477830/b5bfb38b11f7b9cf5bb74db936564db36a6b562b.jpg)
I want the cross-hairs, a flattened semitransparent sphere, (which is a child of the spawner sphere, and offset so you see it on screen.) stays in the same location *on screen* or "in the UI" while the camera moves around the map. The problem is compensating for the cameras position and rotation, I feel like I have tried everything with varying degrees of failure and success, but nothing spot on the desired effect just yet. The targeting system consists of a game object that is currently an elongated transparent sphere, which is attached to a script that fires a ball "forward" relative to said sphere. It's all well an good, if you never move the camera, but that kinda defeats the intent of having the camera rotate around the 'puzzle' of sorts. Where in the center there are blocks to knock down off their foundations by shooting balls, that's the basic premise.Īnyway, I am having trouble getting a solid targeting system in place. Alright, so I've been making this 3D game which consists of a camera that orbits almost an arena type map,