Which is better, shooting a bullet from camera or from the gun itself?

Hi,

I was wondering if it would be a better idea to instantiate a bullet projectile from the camera in the forward direction of the player, directly to the dynamic crosshair, or if it would be better to instantiate it from the gun itself. I prefer to launch it from the camera but, will this give me any problems/difficulties in the long run, like later on? Thanks

[Edit] I also have a muzzle flash/firing animation so it does look convincing. The bullet cant be seen either (bullets don’t get seen anyways.)

3 Answers

3

It’s really up to you, but if you do it from the camera and the camera’s position is on the eye-level of the player model, then you will get things like the player model being crouched behind a car or something, with the gun being obstructed by the car, but the player still being able to shoot over it because the bullets are actually coming out from the eyes.

It’s weird as heck, but this is how most FPS games do it anyway. See any of the COD games for example.

Thanks, makes sense. They come from the GunCamera, which is just a child camera of the main camera (both positioned the same.) So the bullet is pretty much coming straight from eye level to the center of the screen, but I highly doubt the player would ever figure this out because the bullets can't be seen. One thing that does worry me though, is if the player was close to a wall, like right near it, and fired a bullet, the bullet hole would go right to the center, not where the gun is pointing. Anyways, thanks for the answer, I'll mark as accepted.

It should not give you any problems in the long run, however I do strongly suggest you properly shoot from the gun as this will be alot easier to work with (for example if you want to create a 3rd person view or something simular)

I'm not sure whether or not I will add 3rd person view, but the bullets can't be seen. Thanks

It’s a bad idea to instantiate projectiles for bullets, period. You definitely want to use a ray cast.

For a slower projectile, like a rocket, you should instantiate it from the gun. If you instantiate it from the camera, all you will see is its back end getting smaller and smaller until it hits the target. And other players (if any) will see it coming out of your face instead of the gun. I can’t see any reason why you would want to fire it from the camera’s position when it’s just as easy and more accurate to fire it from the gun.

What are the downsides to using projectiles for bullets? They don't have a mesh, and they get destroyed after a certain time has passed. The bullets travel far too fast to be seen (only if the timeScale was like .001, and I'm not planning on adding Slow Motion to the game.) I'm not very experienced with RayCasts either, but I will look into them, thanks for the reply!

problem with instatiating bullets is that it takes up a lot of unneeded processing power, would be even worse if the bullets had rigidbodies. Not everyone has a very good computer, im not even gonna start about mobile devices.

The fact that they travel far too fast to be seen is the reason why it's a bad idea to do it that way. You put unnecessary strain on the physics engine having all those colliders flying around when an instantaneous ray cast would suffice; and can run into problems of bullets passing through walls because they are on one side of a thin box collider one fixedupdate, and on the other side the next, and so never actually colliding.

My bullet projectiles are rigidbody spheres (just for now until I figure something else out) that have a script that ensures they collide, regardless of the frames. Raycasting does seem like a better idea though, I will look into it now.