Hello to all forum, I’m new here more like to say that I really enjoyed the forum and he always helps me.
Well my doubts:
I made a game of first-person shooter using Raycaster, and I used a GUI as a viewfinder, I rotate the “Empty Object” to set the crosshairs in the center of the screen, and she hit the point perfectly, however it only happens to a certain distance, and this makes the gun is not accurate (eh have not wHAT she is now more like an exaggeration) I wonder if you have any script or method so that the sight is constant for all distances.
Thank you for your attention
Eskiel Santana.
Sorry for any grammar errors or violations on the forum.
This method moves the sight to wherever the gun is pointing. If you want to move the gun to wherever the sight is pointing without moving the sight, it would be more like this:
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (camera.main.ScreenPointToRay (Screen.height/2, Screen.width/2, 0), hit) {
transform.LookAt (hit.point);
}
}
error:
The best overload for the method ‘UnityEngine.Camera.ScreenPointToRay (UnityEngine.Vector3)’ is not compatible with the argument list ‘(int, int, int)’.
You need to change it to a Vector3 instead of (int, int, int) as the error is telling you.
You shouldn’t take my code word for word. Theres a reason I add “it would be more like this.” I don’t put too much effort in to keep my code error free on the forums.
Besides, its a good exercise for you to fix the code