- Home /
FPS movement with mouse.
Hello,
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?
Answer by PrimeDerektive · Feb 03, 2011 at 04:33 PM
Didn't test this, but it should work:
var moveSpeed : float = 4.0; var rotSpeed : float = 2.0;
function Update () { if(Input.GetButton("Fire1"){ 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); } }
Glad to help :) Don't forget to mark as answered if you are satisfied.
This script works but the problem is that it disables the collisions and the camera can go through the walls. How can i restore the collisions?
Answer by Borgo · Feb 03, 2011 at 04:02 PM
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:
http://unity3d.com/support/documentation/ScriptReference/
http://unity3d.com/support/documentation/ScriptReference/Input.html
There is some examples too.
Your answer
