How do i make a fps where the gun always shoots realisticly

For example, how do i make it so the bullet goes towards the crosshair(middle of the screen) like call of duty? i dont want a crosshair in the middle of the screen for nothing... i want the bullet to go towards the middle of the crosshair even if the empty is infront of the gun( The gun is to the right of the screen) Thanks!

3 Answers

3

If you want to shoot at the middle of the screen just shoot the bullet from the camera's position in the direction of the camera's forward vector. This will guarantee you will shoot at whatever is exactly dead center of your crosshair.

If I understand him, the gun is 'to the right of the screen' so does he want the bullet to emanate from the on-screen gun muzzle toward the crosshair?

+1 To this, raytrace down the center of the screen and create a fake bullet from the gun. This is how most games do things and will be less annoying when players are shooting "just over" cover.

before each shot make a raycast from camera to forward and hit point returned by raycast is your bullet’s target

now just turn gun to this point and fire - bullet will hit center of screen independent of this point 1 meter from camera or 1 kilometer

better to turn gun smoothly without firing. so keep gun always aiming object at the center of screen

What a deception! Very good solution nontheless. Try to keep your viewport as close to the gunport as possible for best results.

I ended up the reverse way by adjusting the camera angle to the target distance. I give you the advice and don’t try my way. The camera starts shaking everytime you peak around a corner (due to the sudden distance change). Furthermore it’s a very creepy calculation thing…