- Home /
Camera Control/ Rotation C#
Hello, I'm trying to write a script which lets the camera follow the player when he turns. At the moment the camera is following a player which can move forward and backwards but not be able to turn.
I thought about accessing the player's script and the horizontal float value within to tell when it turns but I was unable to.
How can I rotate the player?
My player script is very short so I'll go ahead and drop it in here:
public class RevisedPlayerScript : MonoBehaviour
{
//Two floats for the two axis.
public float horizontal = Input.GetAxis("Horizontal");
public float vertical = Input.GetAxis ("Vertical");
//Empty Vector3
private Vector3 moveDirection = Vector3.zero;
void FixedUpdate()
{
//Two floats continuously change/update with new player inputs.
moveDirection = new Vector3(horizontal, 0, vertical);
//Adding a force.
rigidbody.AddForce (moveDirection * ResourceHandler.speed * Time.deltaTime);
}
}
Any help would be greatly appreciated, thanks!
Comment