- Home /
The question is answered, right answer was accepted (found it myself)
Learn: Survival Shooter aim offset from mouse position
Hi everyone! So I've noticed that in Survival Shooter learn series from Unity when you shoot, line renderer and ray are bit off from mouse position. It looks like this: https://gfycat.com/KlutzySelfishConch I've tried to correct the shooting so the ray is crossing mouse pointer but unfortunately, I couldn't do it after trying everything I could think of. I tried to use "transform.LookAt(point where the ray is hitting the floor plane)" so that the end of the gun barrel object is always looking at the mouse pointer so I could just use "transform.position & transform.forward" when doing the ray cast. It's still off from the mouse pointer. This is the code for the shooting: http://pastebin.com/raw/QhQEjGmv Can someone please help me to fix this problem?
I've found the problem. $$anonymous$$ain camera was rotated around X axis for 30 degrees. When I set it's rotation to 90 degrees so it's top down, I can see no offset. All good. But when I set back to any rotation rather than 90, the offset is back. I even tried to see if ray.direction is changing when switching rotations of the cameras, it's the same so I have no idea why is this happening.
Answer by Dominik523 · Jun 02, 2016 at 06:15 AM
Okay, I've found the problem. Camera has been rotated around X axis fir 30 degrees. I tried to turn it to 90 degrees so it's top down only and the offset is gone. Now I'm not sure is this just visible like that or something else because the the gun is always shooting at the same position no matter how the camera is rotated. Now comes the question how to remove the offset for any camera angle...