- Home /
I need help with this code for clamping my cam
Hi Unity,
I have a problem with my player script i write some code for clamp my camera for the player so far so good everything work but i have an issue with it now ... And i cant find where is my problem now and it's very frustrating here is my code for the mouselook:
// MouseLook code //
mouseX = Input.GetAxis("Mouse X")* Sensibility.x ;
mouseY -= Input.GetAxis("Mouse Y")* Sensibility.y ;
mouseY = ClampAngle(mouseY, clampInDegrees.x, clampInDegrees.y);
var EyeRotation = Quaternion.Euler(mouseY, -90, 0);
Eyelook.rotation = EyeRotation;
myTransform.Rotate(0, Input.GetAxis("Mouse X") * Sensibility.x * Time.deltaTime, 0);
static float ClampAngle(float angle, float min, float max) // For clamping my value //
{
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp(angle, min, max);
}
Eyelook is the "child" Camera of the player
If I disable "Eyelook.rotation = EyeRotation" i can turn on axis horizontal like i want but if i enable this line i'cant turn because on my camera the "y" value is the opposite of the parent so i turn but i can't turn in same time ... and i can't figure why ...
Like you see i don't use CharacterControler beacause i use "http://answers.unity3d.com/questions/155907/basic-movement-walking-on-walls.html " code for my controler
Voila If you want more explanation ask me :)
Thanks in advance
(sorry for my english )