Third Person Shooter - Aiming at Crosshair

So, here’s how I approach it.
First trace the channel setting end to the center of screen and beginning to the position of camera. This will help us actually get the point where the crosshairs are intended to hit.
Second, draw the channel again, but this time the beginning will be your rifle(or any other weapon/spot) and the end will be the point given by the previous channel. This way, the distance of the target is updated in real time and shots are accurate.
Here’s a breakdown using illustrations:
This illustration is just to restate the problem we all are here for…


Now, as per our implementation, we first take inputs from the camera channel before aiming the gun…

With the insights from the camera angle, we can now aim our gun to accurately and precisely shoot at the crosshairs, regardless of distance…

Here’s the implementation for those who’d like to see stuff in action…

{This grab is taken raw from my project, so it contains logic to make the aim imprecise on purpose by using random. But you can still get a good idea}.
Peace

2 Likes