Rotate player with mouse.
I have a camera that I want to rotate. It needs to rotate based on where my mouse its located on the screen, But I want the mouse to stay in the center of the screen (That way the mouse is always on the game screen.) How would I make this happen. Then how would I disable it for a pause screen or something. I have code right now that changes the y rotation based on the mouse posistion, but the mouse does not stay on screen, and it only rotates the y axis and not the x and z. Here is my code: var ray = Camera.main.ScreenPointToRay(Input.mousePosition); var playerRotateSpeed = 10;
var hitdist = 0.0;
var targetPoint = ray.GetPoint((float) hitdist);
var lookPos = targetPoint - transform.position;
lookPos.y = 0;
var targetRotation = Quaternion.LookRotation(lookPos);
camera.transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, playerRotateSpeed * Time.deltaTime);
camera.transform.position = rb.transform.position;
Your answer
Follow this Question
Related Questions
[C#]detect object on mouse look? 1 Answer
Gun-recoil problem C# 0 Answers
Object orientation remains the same while rotating object 1 Answer
how to get object rotation? 1 Answer