Search Unity

How to make the gun in shooting games to move on X and Z axes only?

Discussion in 'Navigation' started by Eco-Editor, Oct 24, 2016.

  1. Eco-Editor

    Eco-Editor

    Joined:
    Jun 29, 2016
    Posts:
    71
    Hello all,

    I'm working on a simulation of a supermarket and has a supermarket cart in it, just like a gun object in unity tutorials, that is a child object of the FPS character. I'd like that object to move only horizontally left and right and go with the character forward and back on the Z axes. Meaning that, while the FPS can look around, I'd like the cart not to be a part of the whole Point of View (as it is with weapon in FPS tutorials), but to act like a cart and "stay" on the ground.

    I've tried multi cameras as suggested in Merry Fragmas part 1 tutorial working with levels, but I got two carts in my game view, one is set in place and the other is moving with the character's gaze, when I set the levels and depth, I have only one cart that is moving with the gaze.

    How would you approach this issue?

    Thanks!
     
  2. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    add rigidbody, then in rigidbody's constraints, u can freeze certain position or rotation.