Jump to content
  • Advertisement
Sign in to follow this  
BrechtDebruyne

First/third person shooter gun-crosshair placement issue

This topic is 2530 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey there,

I'm trying to make a shooter work in both first and third person style, but I'm having some trouble.
I don't know how a gun carried by a player is positioned relative to the crosshair, which is somewhere mid-screen.

I played some quakelive to look at how they solved the problem. They just placed the gun in the middle of the screen, and when a projectile gets fired, it starts from somewhere along the camera's position, and is given a velocity along the look vector of the camera.

I suppose I could do that for my first person view, but then there's still the question of how to manage the collision, since the collisionmesh center of mass position might not be the same of the camera's position (because the gun is not in the middle of the model, but in his right hand).

And then, there's still the question how to do this in third person view. strictly speaking, if we gave the projectile the gun fired, a velocity with a direction along the front vector of the gun's model, the projectile is not going to go smoothly toward the crosshair, because the crosshair only defines a 2D position...

Can anyone please help?
I hope the question is clear, it's not easy to explain but I tried my best...

Much appreciated,
Xcrypt

Share this post


Link to post
Share on other sites
Advertisement
FPS the muzzle flash on a gun helps hide a bit of an offset so the projectile can be closer to the crossair on creation, send the projectile along a vector aiming towards the point the crossair is looking at is one thing, A ray check down the look vector through the middle of the screen to find the position and then do you gun stuff.

TPS have never been too clean with this because its harder to hide the fact that the gun is in a weird offset. But a couple Ideas that come to mind;
Get the vector pointing to the crossair from the gun given its average range. meaning long range it may go to far one way, and short range it may be a bit short.
Place the player so the gun is aligned with the crossair, this could turn out for the best, no messing around, when you fire the gun should look like its firing at the crossair while having the intended accuracy.

Someone else could probably give a better way of doing the FPS, but I think with TPS aligning the gun with the crossair on screen would be most convenient.

Share this post


Link to post
Share on other sites
Hey there, I have tried what you said, it's working a little but it feels quite weird. I do a raycast first with all the collisionmeshes in the scene, if that works, I can have an accurate shot. If there is no intersection point, I will calculate a midrange point for the projectile to float to. When that happens, it feels quite weird...

I would appreciate any more tips!

Share this post


Link to post
Share on other sites
I guess this is the case of shooting at the sky.

In the case of not having anything colliding, use the maximum range of the projectile and cast that distance down the crosshair view. when the projectile finally fizzles or explodes at the max range, it will be at the spot that was under the crosshair in your view.

Your projectiles do have a maximum lifetime or distance correct?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!