- Home /
GetAxis Mouse X on Parent / Mouse Y on Child
float yaw = Input.GetAxis ("Mouse X");
float pitch = Input.GetAxis ("Mouse Y");
Vector3 rotationX = Vector3.zero;
Vector3 rotationY = Vector3.zero;
Vector3 curDirection = player.transform.forward //Player is the playable character moved with "WASD"
if(Mathf.Abs(yaw) > 0.1f)
{
rotationX = yaw * transform.right;
rotationX.Normalize ();
rotationX *= Time.deltaTime * RotateSpeed();
float restrict = Quaternion.LookRotation(curDirection + rotationX).eulerAngles.x;
if(restrict < 90 && restrict > 70 || restrict > 270 && restrict < 290)
{
}
else
{
curDirection += rotationX;
transform.rotation = Quaternion.LookRotation(curDirection);
}
}
This first part is just to move the player and it's camera left and right, which works just fine. The issue i'm having is with the second half of the script. Moving the Mouse Y up and down. I want to be able to move the camera up and down ONLY, without effecting the player.
The player is the parent obj with this script attached - the camera is a child of the player obj I've done a lot of research on this topic, but after a few days of failing at this. I'm just at a loss. I'm sure there has to be something silly i'm missing.
if(Mathf.Abs(pitch) > 0.1f)
{
rotationY = pitch * transform.up;
rotationY.Normalize ();
rotationY *= Time.deltaTime * player.RotateSpeed(); //This is just a float taken from a data script of the player
float restrict = Quaternion.LookRotation(curDirection + rotationY).eulerAngles.y;
if(restrict < 90 && restrict > 70 || restrict > 270 && restrict < 290)
{
}
else
{
curDirection += rotationY;
transform.rotation = Quaternion.LookRotation(curDirection);
}
}
I've tried calling and initializing the camera obj and making the second half of this script transform from the camera. EX: camera.transform.rotation
The way it is now, when moving the mouse up or down, the entire player body rotates with the mouse up or down.
Any help, point of views, opinions would be greatly appreciated.