FPS movement with mouse.


I want to be able to move forward and back, and look left to right only (not strafe), all while holding down the left mouse button and moving the mouse accordingly. Can anyone help?

Didn't test this, but it should work:

var moveSpeed : float = 4.0;
var rotSpeed : float = 2.0;

function Update () {
        var mouseMove : float = moveSpeed * Input.GetAxis ("Mouse Y");
        var mouseRot : float = rotSpeed * Input.GetAxis ("Mouse X");
        transform.Translate(0, 0, Time.deltaTime*mouseMove);
        transform.Rotate (mouseRot, 0, 0);

Learn how to script and learn how to use the Input class.

If you have a specific question aboutyour script, create a detailed and specific question.

Here's some links:



There is some examples too.