I wrote a script to use the mouse to look around, but I’m having trouble, because it is rotating the z axis.
#pragma strict
var mouseSpeed = 0.1;
function Update()
{
//if(rigidbody)
// rigidbody.freezeRotation = true;
Screen.lockCursor = true;
var x : float = mouseSpeed * Input.GetAxis("Mouse X");
var y : float = mouseSpeed * Input.GetAxis("Mouse Y");
transform.Rotate(-y, x, 0.0);
}
You’ll see that I commented out rigidbody.freezeRotation because it didn’t work, nor did simply using “transform.rotation.z = 0;”.
Here are some details about my program:
Capsule [Rigidbody, has movement script]
Main Camera [has mouse look script]
Plane [As a platform]
Cube [As an object to jump on]
Thanks in advance!
rutter
2
When your object rotates around its X axis, its local Y axis changes. If you want to rotate around the world axes, you can specify that:
transform.Rotate(-y, x, 0.0, Space.World);
void Update()
{
//We wanna make sure our cursor is locked
if(Screen.lockCursor == false)
Screen.lockCursor = true;
//Weird Calculationz
yRotation -= Input.GetAxis("Mouse Y") * rotationSpeed * Time.deltaTime;
yRotation = Mathf.Clamp(yRotation, -80, 80);
xRotation += Input.GetAxis("Mouse X") * rotationSpeed * Time.deltaTime;
xRotation = xRotation % 360;
//Rotate camera up+down, player left+right
transform.localEulerAngles = new Vector3(yRotation, 0, 0);
player.transform.localEulerAngles = new Vector3(0, xRotation, 0);
}
This is my new code.