How to make character Aim and shoot at HUD reticle
So, Currently I'm trying to get my character to aim and fire at my HUD reticle/center of the screen. I am using AimOffset which is making it difficult as whenever I turn my upper body the gun and arms unalign with the center of the screen. I know an easy fix would be to disable Yaw rotation for aimOffset but that's not what I want. I want the OffSet to work but also be in sync with the turn rate for the camera. (I have both 1st and first person camera).
How can I get my gun to constantly be aligned with the reticle so that when I fire, the bullets hit the center of screen (Or around it) and continue going on a straight path from there?
asked Mar 16 '19 at 12:04 AM in Using UE4
Shoot From Camera Center
If I understand you correctly, you need to use the forward vector of your camera in order to do your fire logics (LineTrace etc...).
Here is a good tutorial that explains how to do that (more specificly, go to "Shooting Bullets" chapter).
Shoot From Gun Barrel
Hopefully with my (at best vague) drawing, you can understand the main issue with this technique. Namely, that if your gun is not lined up with the camera's center and camera's forward vector (which is, I assume your case), it will only be able to point to the center of the screen for one unique distance (d). So, basically, you will only hit your target if it is at a distance d from the camera. You can mitigate this problem by dynamically calculating d at each frame. For that, you would need to do a LineTrace with the forward vector of the camera and get the distance of the first blocking hit.
So, all in all, I would advice to follow the first method that is much more straight forward and has been proven to work pretty decently.
Hope it helps!
Follow this question
Once you sign in you will be able to subscribe for any updates here