Monday, June 26, 2017

3d - How To Make My First Person Controller turn left and right in unity 5


I want my first person controller to turn left and right instead of just moving straight on that axis.


i have a 3d environment setup in "unity 5" and i am working with the "first person controller" script in unity 5 by default it moves my camera forward,back,left and right what i want is to change the left and right so that it turns the camera instead of moving straight over.



Answer



What you want, is a rotation around the local y-axis when either A or D is pressed.


With the standard assets, this can be achieved quite easily, with the Input manager. To alter the settings, go to Edit->Project Settings->Input.
You should now see the settings for the Input in your Inspector window.



You want to change the Horizontal movement, so expand that and delete the Negative and Positive Buttons, as well as the alt buttons. Alternatively, you can set your preffered keys for horizontal movement. For Q and E, it would look like this:
Horizontal Input


If you look through the Settings, you can see a "Mouse X" setting. If you want to remove rotation with the mouse, you can directly edit this, or increment the Size field by 1. This will add another property at the end of the list, which you can edit.


Here are the important changes that need to be done, in order to work with the standard assets:



  • Name needs to be set to "Mouse X"

  • Negative and Positive Buttons need to be set, A and D in your case

  • Type has to be Key or Mouse Button


Also, you will probably want to set a high Gravity, so that the rotation stops quite soon, after releasing a key. You can also play around with the sensitivity, to get a faster or slower rotation.



The final input could look similar to this: Mouse X Input


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...