MouseLookiPhone javascript version?

Is there a javascript version of the MouseLookiPhone.cs script that came with the Warehouse example? I am working on using swipes across the screen to rotate the camera. I think what is being done in the example script would make a lot more sense for me (and be more adoptable) if it were in javascript.

Yes, right here. :wink: (Actually I did this a while ago for myself.)

/// MouseLook rotates the transform based on the mouse delta.
/// Minimum and Maximum values can be used to constrain the possible rotation

/// To make an FPS style character:
/// - Create a capsule.
/// - Add a rigid body to the capsule
/// - Add the MouseLook script to the capsule.
///   -> Set the mouse look to use LookX. (You want to only turn character but not tilt it)
/// - Add FPSWalker script to the capsule

/// - Create a camera. Make the camera a child of the capsule. Reset it's transform.
/// - Add a MouseLook script to the camera.
///   -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)
@script AddComponentMenu("Camera-Control/Mouse Look")

enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
var axes = RotationAxes.MouseXAndY;
var sensitivityX : float = 15;
var sensitivityY : float = 15;

var minimumX : float = -360;
var maximumX : float = 360;

var minimumY : float = -60;
var maximumY : float = 60;

private var rotationX : float = 0;
private var rotationY : float = 0;

private var inputX : float = 0;
private var inputY : float = 0;

private var originalRotation : Quaternion;

function Update ()
{
	if (axes == RotationAxes.MouseXAndY)
	{
		// Read the mouse input axis
		rotationX += inputX * sensitivityX;
		rotationY += inputY * sensitivityY;

		rotationX = ClampAngle (rotationX, minimumX, maximumX);
		rotationY = ClampAngle (rotationY, minimumY, maximumY);
		
		var xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
		var yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
		
		transform.localRotation = originalRotation * xQuaternion * yQuaternion;
	}
	else if (axes == RotationAxes.MouseX)
	{
		rotationX += inputX * sensitivityX;
		rotationX = ClampAngle (rotationX, minimumX, maximumX);

		xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
		transform.localRotation = originalRotation * xQuaternion;
	}
	else
	{
		rotationY += inputY * sensitivityY;
		rotationY = ClampAngle (rotationY, minimumY, maximumY);

		yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
		transform.localRotation = originalRotation * yQuaternion;
	}
}

function Start ()
{
	// Make the rigid body not change rotation
	if (rigidbody)
		rigidbody.freezeRotation = true;
	originalRotation = transform.localRotation;
}

static function ClampAngle (angle : float, min : float, max : float) : float
{
	if (angle < -360.0)
		angle += 360.0;
	if (angle > 360.0)
		angle -= 360.0;
	return Mathf.Clamp (angle, min, max);
}

function SetInput (rightStickInput : Vector2)
{
	inputX = rightStickInput.x * 0.1;
	inputY = rightStickInput.y * 0.1;
}

–Eric

Awesome! That’s a big help. Thanks.