- Home /
Question by
PlayZzOfficial · Jul 21, 2021 at 12:16 AM ·
c#player movementcamera rotate
How to rotate Camera with Arrow Keys
My thought: Hi, So I was watching a tutorial on player rotation which the player rotates when moving that's what i wanted at first until I realized how confusing it can be with my cinamachine camera.
Question: So my Arrow keys = camera look position; wasd = movement., but camera look is true direction how would I accomplish this??
Movement Script -
player movement:
void Update()
{
movementDirections.x = Input.GetAxisRaw("Horizontal");
movementDirections.z = Input.GetAxisRaw("Vertical");
}
//-----//
void FixedUpdate()
{
Move();
}
//-----//
void Move()
{
var movement = new Vector3(movementDirections.x, 0, movementDirections.z).normalized * movementSpeed;
movement.y = playerRigidbody.velocity.y;
playerRigidbody.velocity = movement;
}
player rotation:
void Update()
{
Rotate();
}
void Rotation()
{
if (movementDirections != Vector3.zero)
{
rotate = Quaternion.LookRotation(movementDirections, Vector3.up);
playerRigidbody.rotation = Quaternion.RotateTowards(playerRigidbody.rotation, rotate, rotationSpeed);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613040557im_/https://answers.unity.com/themes/thub/images/avi.jpg)