- Home /
controls like old game
I want to make a camera and character movement control set up that works like this:
- W to walk forward.
- A to rotate camera to the left.
- D to rotate camera to the right.
- S to walk back.
- Mouse to look up and down or tilt the camera.
I have some code that does everything but the turning the camera to the left and right when I press the A or D key, instead the player [incorrectly] moves in that direction.
Here is the code I'm working with. I know it has something to do with rotate, transform and get key. Anyone that can point me in the right direction?
private var fpcMouse; private var camMouse;
function Start () {
fpcMouse = gameObject.Find("Player").GetComponent("MouseLook");
camMouse = gameObject.Find("Main Camera").GetComponent("MouseLook");
}
function Update () { if (Input.GetKeyDown(KeyCode.Q)) {
Screen.showCursor = !Screen.showCursor;
Screen.showCursor = true;
fpcMouse.enabled = !fpcMouse.enabled;
camMouse.enabled = !camMouse.enabled;
}
}
Answer by fireDude67 · Nov 11, 2010 at 01:28 AM
Have you tried the FPSController yet?
Also you can attach a camera component to your character and do something like:
transform.Rotate(0, Input.GetAxis("Horizontal"), 0);
However this will rotate the character using both A/D and left arrow/right arrow. You can change this using the input manager
yes but the FPSController moves the camera with the mouse in all directions and all i want is to tilt with the mouse I will take another look at it maybe I can modify it thanks
sweet thanks I will check it out some time this weekend its wife time today so no unity for me lol
if you use FPSController, then remove the $$anonymous$$ouseLook script on the First Person Controller gameObject, then add a script to it like the one above
Your answer
![](https://koobas.hobune.stream/wayback/20220613082655im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Make camera follow cylindrical track 1 Answer
Move RigidBody character relative to camera. 2 Answers
AddForce to Camera 1 Answer
RTS Camera Rotation and Movement 0 Answers