- Home /
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!
Answer by Bryan 4 · Apr 11, 2011 at 08:17 PM
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?
Yes but this doesnt look realistic a bullet just co$$anonymous$$g out of nowhere in the middle
You run into more issues if you want the offset projectile, as it will add perspective calculations for ensuring the gun itself hits the target in the crosshair. $$anonymous$$ost games fake this by using a muzzle flash and shooting an invisible projectile from the camera to the target, bullets are never seen as they travel too fast regardless.
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.
Answer by ScroodgeM · Jul 22, 2012 at 09:16 AM
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
Answer by Nanity · Jul 22, 2012 at 10:02 AM
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...