Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

FPS Camera issue

Discussion in 'Scripting' started by Not_Sure, Aug 10, 2018.

  1. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,541
    This is embarrassing, but I'm not exactly sure how to have the weapons off center AND hit the middle of the screen.

    Like this should be how to make an FPS 101, but I'm not seeing any tutorials that mention just this.

    I've got the weapon off center and weapon camera.

    But if the shot comes out of the weapon then it is off center.

    I tried to keep the weapon center and offset the weapon camera, but then the shot doesn't match the weapon.

    I also tried to have the gun point at the collision of a raycast shot out of the main camera, which actually worked pretty well, but has... issues.

    Lastly, I tried to shrink down the weapon so the difference wasn't as great, but then lighting and shadows don't match up.

    Any suggestions of links to tutorials?
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Doesn't that depend on how you are doing your shooting? In a 3D environment, the concept of shooting "the middle of the screen" is a little skewed. The "middle of the screen" extends (potentially) infinitely along the "forward" axis. Which of those points is the gun aiming at?

    Presumably, you would either raycast through the screen centre along the forward axis to see if something was hit. Or, similarly, raycast from the gun's perspective. Or otherwise, create a projectile and launch it from the gun'l position along the gun's "forward" axis and let the physics engine resolve it (assuming the projectile isn't moving too fast).

    I don't have access to Unity at the moment but, if I recall correctly, can't you create a new 3D project starting off with an FPS controller, a bubble gun and a little demo scene with some obstacles to shoot at? Maybe you could compare against that to see how your scene differs.