Search Unity

Third Person shooter with Crosshairs

Discussion in 'Scripting' started by Robster95, Jun 8, 2021.

  1. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    Hello everyone,
    I am making a third person shooter with some friends and I have the gameplay working with shooting already implemented but the problem is I have the weapons shooting out of the forward vector of the weapon.

    I want to incorporate Crosshairs that stay in the middle of the screen and have the weapons shoot towards that. I know I can do a ViewportttoRay to have the bullets shoot from the camera to the crosshairs like how Jason does it in this video



    If I were to do this and try to visualize the bullet in game ( possibly with a line renderer), The raycast will then come from the camera and the linerenderer will then come from the camera too if I only try the viewporttoray. if I shoot from the viewport and visualize from the forward vector of the weapon, I dont think the two will match up (viewporttoray and visualization from the guns forward vector)

    If anyone knows of a way to make this work with both visualization and an accurate shot towards the crosshairs please let me know!

    Thank you
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Yeah they won't line up... I think games fudge this by going ADS close to screen center, like Gears:

    Screen Shot 2021-06-07 at 7.08.29 PM.png

    I don't have Gears handy anymore but I bet you the bullets were actually traveling down the camera when in ADS.

    When not in ADS the bullets tended to spray around a lot more and I think that was probably to hide this offset.

    Take a look for yourself:

     
  3. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    Yeah sounds about right. I already have a decent shooting mechanic where the bullets get a bullet spread the more you shoot. It works from both spots, the viewporttoray and the forward vector of the gun.

    Do you have any idea's on ways I can incorporate these to work together and not make it look weird or do you think the viewporttoray would be best? This game i'm working on doesn't have an aim down sights setting. Just hip fire basically
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Might not even notice if there's not a lot of cover up close to the player. If things are mostly open, most players may not notice.

    And even if they DO notice, if you make the gameplay fun enough, they won't care!
     
    Robster95 likes this.
  5. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    Ok I hope so! I'll figure it out and try to update you!
     
    Kurt-Dekker likes this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Watched quite a bit of that Gears video I posted above... I really enjoyed that and other Gears. I don't recall ever once during any of the Gears series thinking "Damn, I can't shoot around this corner..."

    I think they just were very forgiving and assumed the bullets WERE flying from camera center.

    Obviously when you went into cover they could control camera placement precisely, and that's where a lot of the firing happened.

    What a great game series. Absolute powerhouse of art and game design.
     
    Robster95 likes this.
  7. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Spawn the bullet at the muzzle with a trajectory to intercept the point where the raycast hits -- or at ~200 units along the ray if there is no hit -- as long as that projected impact point is ahead of the player. If it's not ahead of the player, you can either shoot it wildly out of the gun anyways or not at all depending on your game. The player won't care about the bullet taking a slightly odd exit angle at that point, as you can see around 2:10:15 in the video, but tracers flying through the middle of the camera would definitely feel weird.
     
    Last edited: Jun 8, 2021
    Robster95 likes this.
  8. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    I think I realized something when I was reading this and I'm not sure if I interpreted what you were saying correctly

    but,

    After reading what you said I was thinking of of shooting a raycast from the Viewporttoraycast with a reference to an endpoint and have another raycast shoot from the weapons forward vector and have them intersect depending on the distance.

    After rereading your response it does seem that I interpreted it correctly but yes the main reason I posted this was to fix the problem of the bullets flying out of the camera.