Hello people,
im new to unity and gamedev at all and most of my coding experience was with Actionscript.
Im trying to sync a cubes rotation on y axis with the cam, (both parented with the same prefab), by modifing the standard mouse look script. So I added a function and call it, when ever the mouse moves on x-achsis, but the cube doesnt rotate as i assumed it. It moves slowly…
can someone give me a hint with this?
Heres is the script so far
public class MouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationY = 0F;
GameObject playerModel;
//Component playerModel;
void Update ()
{
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
movePlayerModel();
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
movePlayerModel();
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
void movePlayerModel()
{
playerModel.transform.Rotate (
playerModel.transform.rotation.x,
transform.rotation.y,
playerModel.transform.rotation.z
);
}
void Start ()
{
playerModel = GameObject.Find("PlayerModel");
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
}