- Home /
how to get mouselook that the mouse X and mouse Y wasn't depend on X and Y axis when i got to rotated in Z axis?
i have this script :
#pragma strict
var lookSpeed = 3.0;
var moveSpeed = 1.0;
var scrollspeed = 100;
private var rotationX = 0.0;
private var rotationY = 0.0;
private var rotationZ = 0.0;
function Update ()
{
rotationX += Input.GetAxis("Mouse X")*lookSpeed;
rotationY += Input.GetAxis("Mouse Y")*lookSpeed;
rotationZ -= Input.GetAxis("Mouse ScrollWheel")*scrollspeed;
transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
transform.localRotation *= Quaternion.AngleAxis(rotationZ, Vector3.forward);
transform.position += transform.forward*moveSpeed*Input.GetAxis("Vertical");
transform.position += transform.right*moveSpeed*Input.GetAxis("Horizontal");
}
i put this script in camera. it for moving and rotate my kamera. that's script was work. but, when have rotate (my camera) in Z axis, mouse X still depend on X axis, and mouse Y still depend on Y axis...
how can i get mouselook that the mouse X and mouse Y wasn't depend on X and Y axis when i got to rotated in Z axis?
(When i have rotate in Z axis, if i take a positif mouse X,it look change like our eyes look at the right side, otherwise too,and if i take positif mouse Y,it look change like our eyes look at the up side, otherwise too)
(i'm sorry if i make a bad grammar in my english)
use parents, make a Empty GameObject andd assigs as child your camera, in the empty GameObject make then move towards and rotate in X and Y, and in the camera, only rotate in Z
i have tried it. but when i have rotate in Z axis, if i take a positif mouse X,it not look change like our eyes look at the right side, and otherwise, in mouse Y too...
i have change my kamera script on my builded project. here:
this use for move : #pragma strict var moveSpeed = 1.0;
function Update () {
transform.position += transform.forward*moveSpeed*Input.GetAxis("Vertical");
transform.position += transform.right*moveSpeed*Input.GetAxis("Horizontal");
}
this use for rotate z axis :
#pragma strict
var scrollspeed = 100;
private var rotationZ = 0.0;
function Update () {
rotationZ -= Input.GetAxis("$$anonymous$$ouse ScrollWheel")*scrollspeed;
transform.localRotation = Quaternion.AngleAxis(rotationZ, Vector3.forward);
}
this use for xy axis :
#pragma strict
var lookSpeed = 3.0;
private var rotationX = 0.0;
private var rotationY = 0.0;
function Update () {
rotationX += Input.GetAxis("$$anonymous$$ouse X")*lookSpeed;
rotationY += Input.GetAxis("$$anonymous$$ouse Y")*lookSpeed;
transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
}
(use DWSA key for movement; in my builded project that i have shared in link above)
Your answer
Follow this Question
Related Questions
how to add force in z direction in input.getmousebuttondown ? 1 Answer
Space Camera Issue. 1 Answer
How to make a mesh into a FirstPerson Character? 2 Answers
Return Camera Rotation Z axis to 0 2 Answers