- Home /
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.)
Answer by guitarxe · Dec 12, 2013 at 12:16 AM
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 co$$anonymous$$g 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.
CoD and other modern FPS games mask this by, obviously, showing a muzzle flash on the gun when being fired, which of course gives a strong believable expectation that the bullet comes from the gun, but also for drawing the tracer bullets, these are also seen as co$$anonymous$$g from the gun's position, not from the camera's position. Combined, there really isn't any reason for the player to think the bullets don't actually come from the gun itself.
The times when this illusion is broken and the player can see what's going on, like the example I provided or the one you mentioned with the wall, they don't really cause much of a problem for a player's enjoyment of the game. At least, I've never heard of people creating a big fuss about it. It's just a "heh, that's funny, so that's how they do it" moment for most gamers, probably.
And in fact, with your wall example, that's not as big a problem as you think. The bullet hole decals are drawn where the crosshair is pointing to. That's where the player expects the bullets to be. Especially since even though the player is right up to a wall, the 1st person model of the gun still points forward, where in real life this would have to be lowered in order to press closer to the wall. This gives the player an illusion of distance between them and the wall.
Answer by EX_Darius · Dec 12, 2013 at 12:16 AM
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
Answer by Kiloblargh · Dec 12, 2013 at 12:18 AM
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 $$anonymous$$otion 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.
$$anonymous$$y 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.
Your answer
Follow this Question
Related Questions
Zooming in with a gun, Halo style. 2 Answers
Control amount of bullets 2 Answers
Gun is shooting based on movement not camera rotation? 1 Answer
Raycasr in my fps? 1 Answer
Make a Gun fire multiple times 3 Answers