- Home /
Aiming to the crosshair
Hello,
I'm currently busy on a sort of FPS game, I've got a crosshair in the middle of the screen but I need help with the positioning of the crosshair. I want to shoot to the crosshair, I'm using a raycast to shoot. I could use tips and "tutorial" like answers. I set up a little mini script showing whats the main thing my gun is doing:
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
if(Physics.Raycast(spawn.position, direction, hit, range)){
}
That's about it what I'm using the rest is just defining what the raycast hit.
Thanks in advance!
-Hybris
Should be able to find something already posted in here on this. I've seen the same question asked before at least once.
Answer by rutter · May 05, 2012 at 06:45 PM
You'll probably want to use Camera.ScreenPointToRay(), passing in some useful data like the center of the screen, mouse cursor position, or so on.
You can see an example here: http://answers.unity3d.com/questions/23683/air-strike-shoot-aiming-at-cross-hairs-in-middle-o.html
Here's the script reference page: http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenPointToRay