x


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!

more ▼

asked Apr 11 '11 at 07:25 PM

niceperson87 gravatar image

niceperson87
12 7 8 8

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Apr 11 '11 at 08:17 PM

Bryan 4 gravatar image

Bryan 4
454 7 8 19

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?

Apr 11 '11 at 08:39 PM DaveA

Yes but this doesnt look realistic a bullet just coming out of nowhere in the middle

Apr 11 '11 at 08:45 PM niceperson87

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. Most 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.

Apr 12 '11 at 04:30 PM Bryan 4

+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.

Jul 20 '12 at 04:10 PM Muuskii
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Jul 22 '12 at 09:16 AM

ScroodgeM gravatar image

ScroodgeM
7.6k 2 6

(comments are locked)
10|3000 characters needed characters left

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...

more ▼

answered Jul 22 '12 at 10:02 AM

Nanity gravatar image

Nanity
68 2 4

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1176
x446
x329
x308

asked: Apr 11 '11 at 07:25 PM

Seen: 1405 times

Last Updated: Jul 22 '12 at 10:02 AM