- Home /
Make 3rd-person character smoothly rotate with mouse camera
Heey,
I'm making a 3rd-person game, and I want the character to rotate along with the mouse I mean, if I mouse with my mouse, to a certain point, I want my character to rotate to that position aswell! Smooth enough so someone's head can't go crazy.
I'm using this for my character: (http://hastebin.com/sorufodope.cs)
public class CharacterMovement : MonoBehaviour {
public CharacterController controller;
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update () {
float v = Input.GetAxis ("Vertical");
float h = Input.GetAxis ("Horizontal");
controller = GetComponent<CharacterController> ();
if (controller.isGrounded) {
moveDirection = new Vector3 (0, Camera.main.transform.localRotation, v);
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= speed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move (moveDirection * Time.deltaTime);
}
}
What's next?
Thanks in advance, Pr0totype2
There are many duplicate questions/answers on this topic already. A quick Google search showed tons including those with vid tutorials on setup. What have you tried and include relevant code.
I can barely find something that helps me...
Your answer
Follow this Question
Related Questions
How to allow camera to complete an upside down rotation while using LookAt() 0 Answers
Camera movement according to rotation and actual position RTS 1 Answer
RTS Camera control - Rotation with MMB 0 Answers
Camera defaulting to -90 Y 0 Answers
Get camera rotation constrained to left/right (ie. yaw)? 2 Answers