Rotating the player with mousePosition problem.
I am trying to make the character of my game rotate with the mouse position left and right. I also want the character to be able to look up and down as well as being able to move in those directions. My character will be able to fly but that would be easy to add in later. The problem I am having is that the current code I am using only allows the character to rotate left and right (rotates faster the further the cursor is moved downwards and slows the further to the top of the screen). I am hoping for some suggestions or hints as to what I am missing. This is my current code: Plane playerPlane = new Plane (Vector3.up, transform.position);
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
float hitdist = 0.0f;
if (playerPlane.Raycast (ray, out hitdist)) {
.
Vector3 targetPoint = ray.GetPoint (hitdist);
Quaternion targetRotation = Quaternion.LookRotation (targetPoint - transform.position);
transform.rotation = Quaternion.Slerp (transform.rotation, targetRotation, cSpeed * Time.deltaTime);
}
Plane playerPlane = new Plane(Vector3.up, transform.position); belongs above the Ray ray line. got cut off for some reason.