1
\$\begingroup\$

Hi I am developing a First person game but would like to use the mouse to move on a click to move as opposed to the keys. I also need to disable Y movement and restrict the x movement to 180. What ever values I enter into the input manager, it seems to be ignoring them as I still have both x and y when I run the game.

I dabbled with the standard unity FPS but is seems very jagged on movement and from what I can see being a new user, their doesn't seem to be a way to restrict y movement. Can someone help with this or suggest a good tutorial on this type of movement. Thanks

\$\endgroup\$
1
  • \$\begingroup\$ You can lock y-axis movement in the editor in you're using a Rigidbody. If you're using a Character Controller then you can simply add a script to it that will take the y-axis position at start and then apply it in every update, so it can't move up-down. \$\endgroup\$ – zoran404 Aug 5 '15 at 11:59
1
\$\begingroup\$

You can use: transform.Translate(Input.GetAxis("Mouse Y"), 0, Input.GetAxis("Mouse X"));

Or if you want to use physics: rigidbody.AddForce(Input.GetAxis("Mouse Y"), 0, Input.GetAxis("Mouse X"));

\$\endgroup\$
0
\$\begingroup\$

Go to the code and find the input.Axis function and add two if statements. ~If greater than 180 =180. And the same for 0. I would recommend using global variables for the limits so you can change them in the future in the editor.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.