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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Can't get gun to aim at centre of the screen

Discussion in 'Editor & General Support' started by Archiboi, Nov 11, 2022.

  1. Archiboi

    Archiboi

    Joined:
    Jan 27, 2022
    Posts:
    4
    I'm making an FPS shooter in unity, where the bullets are supposed to travel out of the gun. I'm trying to use a method I found from a youtube video to point the gun at the center of the screen -

    I can't quite figure out how to make the barrel of the gun point at the aim transform though.
    Does anybody know how to fix this?
     

    Attached Files:

    Last edited: Nov 11, 2022
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,019
    do you want to point at fixed distance away, or at the raycast hitpoint? (if hitpoint: you get that rotation, when near objects..)

    also, that script has one typo:
    fixedUpdate()

    should be
    FixedUpdate()
     
  3. Archiboi

    Archiboi

    Joined:
    Jan 27, 2022
    Posts:
    4
    Thanks for fixing my typo!
    I would like the gun to aim at the Raycast hitpoint, and reset it to it's default position when the raycast is not hitting anything.
    What I'm having trouble figuring out is how to get the barrel of the gun to actually point towards the raycast hitpoint (or aim transform).
    any ideas?
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,019