I’ve looked around the board to find my answer. I’m a total zero at scripting. I have a project and I need to control my camera as if it was like an helicopter but as a first person.
What I want is:
W, A, S, D : move forward, backward, strafe left strafe right
Space bar: move up
Left Ctrl: Move down
The “mouse look control” of Unity already behave as I want.
I know it may sound simple for a lot of you but I’m new to Unity.
The MouseLook script may do what you want, specially if you choose MouseXandY in the Axes field (MouseLook component in the Inspector). To move the camera, this simple script vaguely based on the CharacterController.Move example can do the job:
var speed : float = 6.0;
function Update() {
var moveSpeed : Vector3;
// calculate the lateral speed (AD and/or joystick X)
moveSpeed.x = speed * Input.GetAxis("Horizontal");
// calculate the forth/back speed (WS and/or joystick Y)
moveSpeed.z = speed * Input.GetAxis("Vertical");
// generate a -1/0/1 output like the GetAxis above for up/down movement
var up: float = 0;
if (Input.GetKey("space")) up = 1;
if (Input.GetKey("left shift")) up = -1;
// calculate the up/down speed
moveSpeed.y = speed * up;
// move the camera by the displacement since the last Update
// (moveSpeed * Time.deltaTime converts speed to displacement)
transform.Translate(moveSpeed * Time.deltaTime);
}
Scripting is not that hard: try to understand and even improve this simple script - using different speeds to move up/down, left/right and forth/back, for instance.