Question by
White-Yankee · Apr 16, 2018 at 11:50 AM ·
unity 5camerarotationplayerthird-person
Camera rotate X degree based on player rotate
Unity 3d - Thirdperson
Hello everyone, i am trying to achieve an effect that smoothly rotates player to camera forward direction, i have achieved this while player is moving but i want to cap it at a certain degree like the image below display when player is not moving.
If player camera rotates 45 degree left the player will align its forward to cameras forward there for reset the cap based on player forward.
Example
here is part of my camera code:
// Player allign to Camera
playerRot = pController.transform.rotation; // get player rotation
cameraRot = playerCamera.transform.rotation; // get camera rotation
smoothRot = Quaternion.Slerp(playerRot, cameraRot, playerRotSmoothTime * Time.deltaTime); // smooth rotate
if (pController.isMoving)
{
pController.transform.eulerAngles = new Vector3(playerRot.eulerAngles.x, smoothRot.eulerAngles.y, playerRot.eulerAngles.z); // apply rotation
}
if (!pController.isMoving)
{
rotClampMinMax = new Vector2(playerRot.eulerAngles.y - (thirdFreeLookHorizontal / 2), playerRot.eulerAngles.y + (thirdFreeLookHorizontal / 2));
if (playerCamera.transform.forward.y <= rotClampMinMax.x && playerCamera.transform.forward.y > playerRot.eulerAngles.y + 180) { print("left side"); } // get current mouse rotation
if (playerCamera.transform.forward.y >= rotClampMinMax.y && playerCamera.transform.forward.y < playerRot.eulerAngles.y - 180) { print("right side"); } // get current mouse rotation
}
rotate-circle2.jpg
(43.3 kB)
Comment
Your answer
Follow this Question
Related Questions
Como desplazar la camara en un juego en tercera persona 0 Answers
Making the player the camera's axis of rotation. 0 Answers
Smooth Look at... 2 Answers
Making camera follow the player the right way 0 Answers
Make character face movement direction 0 Answers