|
Hi I am using First Person Control, I disabled MouseLook, so I can only control the game by keyboard arrows.But the arrows can only go forward/backward/right/left, I cannot turn around. I want when I press the right arrow, I will turn 45 degrees or 90 degrees, then I can use the up arrow to move forward. How can I do this? Thanks
(comments are locked)
|
|
In FPSInputController.js, the line
controls your movement on the x-axis/sideways (horizontal input keys) and z-axis/in&out (vertical input keys). If you remove 'Input.GetAxis("Horizontal")' you'll no longer be able to strafe. You can add a line right after it to rotate you along the y-axis based on the horizontal input keys: Sorry I can't find FPSInputController.js, where should I put these code? Thanks!
Nov 17 '10 at 11:05 PM
Lucy
To edit FPSInputController.js, select the First Person Controller in the scene and look at the Inspector. Click on the little blank page icon that says "FPSInputController (MonoScript)" beside it. This will highlight and focus the script in the Project pane (located in Standard Assets/Character Controllers/Sources/Scripts)
Nov 26 '10 at 09:02 AM
ryleigh
Hello, Hopefully someone still looks at this thread. Ryleigh, I am trying to follow what you said. I got rid of the 'Input.GetAxis("Horizontal")' then inputed the other line but would get one error after another. Do you by chance know why? This is exactly what I'm looking for and have been stuck for ages!
Apr 15 '12 at 11:00 PM
BluEye
(comments are locked)
|
|
changed the first 2 if's so it should work better now: function Update () { if (Input.GetKey(KeyCode.DownArrow)) transform.Translate(0, 0, -1); if (Input.GetKey(KeyCode.UpArrow)) transform.Translate(0, 0, 1); if (Input.GetKey(KeyCode.RightArrow)) transform.Rotate(0, 1, 0); if (Input.GetKey(KeyCode.LeftArrow)) transform.Rotate(0, -1, 0); } as i said above use this in a new java script and put it on your camera I have the First Person Control, so I put it on the camera which inside the First Person Controller, is that right? When I press the left/right arrow key, it's not turing, it still goes parellel. Another question, how can I disable my mouse? I want to use arrow keys to go forward/backward or turn around, use mouse just for clicking buttons Thank you
Nov 22 '10 at 12:15 AM
Lucy
for me the script i put up works fine on the camera but i have not tried putting it in a 'first person controller'. As for the mouse are you asking to make it stop moving your character, in which case you can just find that part of the script and delete it. Or you can hide the mouse but if it is going to be used for click then this would be useless (i don't understand what you mean by disable)
Nov 22 '10 at 10:40 AM
Scribe
Thanks for replying. At the moment, I can use mouse to point sky and point ground, the mouse can be pointing to anywhere, it makes me busy to use keyboard to go forward/backward, and use mouse to change directions
Nov 23 '10 at 03:55 AM
Lucy
so if you want to stop moving the camera with the mouse you will have to find that part of the script and get rid of (sorry still not quite sure what your asking the mouse to do). P.S did the script i posted work in the end or are you still having problems (if your using the character control script it gives it might be that it is already using a code to move forward, backwards and side-to-side and this part of it might also need to be deleted)
Nov 23 '10 at 05:32 PM
Scribe
sorry it doesn't work. In First Person Controller, I changed minimumY and maximumY to 0, now the mouse won't go up and down, but no idea of X Thank you
Nov 25 '10 at 04:00 AM
Lucy
(comments are locked)
|
|
Hi Lucy and Scribe, I have been reading your post an the indications from Scribe and finally got it work! As I couldn't attach the file, below you'll find the complete code. Regards, German ==================================================================
(comments are locked)
|
|
function Update () { if (Input.GetKey(KeyCode.UpArrow)) transform.Translate(Vector3.forward * Time.deltaTime); if (Input.GetKey(KeyCode.DownArrow)) transform.Translate(-Vector3.forward * Time.deltaTime); if (Input.GetKey(KeyCode.RightArrow)) transform.Rotate(0, 1, 0); if (Input.GetKey(KeyCode.LeftArrow)) transform.Rotate(0, -1, 0); } where should I put these code? Do I create a new .js file and attach it into the main camera? Thanks
Nov 21 '10 at 07:47 PM
Lucy
yep you make a new .js file and copy and paste this code. then put it on the camera it should work
Nov 21 '10 at 08:04 PM
Scribe
(comments are locked)
|

What do you mean exactly by '45 or 90 degrees'? Do you want the character to turn at fixed angular intervals? (E.g. every time you press the left arrow key the character turns 45 degrees to the left.)
Hi Jesse:) Sorry for the confusing. You know when you play a 3D game, you only use arrows to go straight or turn around, then use mouse to click. So I want to make my game like that, but the arrow doesn't do turnings, it only moves like parallel. It's like I walk toward left without turning my face to left...