- Home /
SOLVED ROTATE PLAYER ACORDING TO CAMERA ROTATION (using cinemacine and custom cameras) (player direction relative to camera)
After, too much time and too many problems, i eventually got this:
float X = Input.GetAxis("Mouse X");
r.transform.Rotate(0, X, 0);
r.constraints = rigidbodyConstraints.FreezeRotationZ|RigidbodyConstraints.FreezeRotationX;
add this constraint for good measure
and be 100% SURE you change the default Y AXIS speed from 3 and X AXIS speed=300 to Y AXIS1 and X AXIS 1 with 0.5 for sensitivity on your "mouse X" and/or "mouse Y" axis (that is under the edit > project settings tab, then find input manager in project settings and open the axes arrow
for anyone that stumbles across this looking for a way to rotate a player with your cinemachine camera, here you go, use under for a custom camera
mouseX += Input.GetAxis("Mouse X") * RotationSpeed;
mouseY -= Input.GetAxis("Mouse Y") * RotationSpeed;
mouseY = Mathf.Clamp(mouseY, -35, 60);
transform.LookAt(Target);
if (Input.GetKey(KeyCode.LeftShift))
{
Target.rotation = Quaternion.Euler(mouseY, mouseX, 0);
}
else
{
Target.rotation = Quaternion.Euler(mouseY, mouseX, 0);
Player.rotation = Target.transform.rotation;
}
alternative
public float RotationSpeed = 1;
public Transform Target, Player;
float mouseX, mouseY;
void Start()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
void LateUpdate()
{
CamControl();
}
void CamControl()
{
mouseX += Input.GetAxis("Mouse X") * RotationSpeed;
mouseY -= Input.GetAxis("Mouse Y") * RotationSpeed;
mouseY = Mathf.Clamp(mouseY, -35, 60);
transform.LookAt(Target);
if (Input.GetKey(KeyCode.LeftShift))
{
Target.rotation = Quaternion.Euler(mouseY, mouseX, 0);
}
else
{
Target.rotation = Quaternion.Euler(mouseY, mouseX, 0);
Player.rotation = Target.transform.rotation;
}
}
Your answer
Follow this Question
Related Questions
How can I disable my player movement and camera movement when I hit I to open my inventory? 2 Answers
Enemys jittering when moving 1 Answer
Third person camera gets closer to the player 0 Answers
Camera relative rigidbody third person player movement 1 Answer
Rigidbody Controller move forward in the direction of the camera 0 Answers