# How do I add camera rotation while moving a player sideways?

After experimenting for a couple of days I still haven’t found a decent manner to rotate a player cam horizontally with the A and D keys (assuming classical mapping). I am aiming for something like the first DOOM’s movement. How do I achieve this?

``````using UnityEngine;

using System.Collections;

public class MoveyCube : MonoBehaviour

public float maxSpeed = 6f;
public float maxAcelleration = 100;
Vector3 movement;
public float acelleration = 0f;
Rigidbody playerRigidbody;
Vector3 rotatevector;
int rotspeed;

void Awake ()
{
playerRigidbody = GetComponent <Rigidbody> ();
}

void FixedUpdate ()
{
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");

Move (h, v);

if (acelleration < maxSpeed && Input.GetKey (KeyCode.W) || Input.GetKey (KeyCode.S) || Input.GetKey (KeyCode.A) || Input.GetKey (KeyCode.D))
{
acelleration += 1;
if (acelleration >= maxSpeed)
{
acelleration = maxAcelleration;
}
}
else
{
acelleration -= 1;
if (acelleration <= 0)
{
acelleration = 0;
}
}
}

void Move (float h, float v)
{
movement.Set (h, 0f, v);
movement = Camera.main.transform.TransformDirection(movement);
movement = movement.normalized * acelleration * Time.deltaTime; // Anti diagonal extra speed measure

playerRigidbody.MovePosition (transform.position + movement);
rotatevector.Set (0, h, 0);
Camera.main.transform.Rotate(rotatevector * Time.deltaTime);

}

}
``````

You want the mouse to control the player’s rotation left and right, and have the camera follow the player and its rotation (pretty much, unless you want smoothing which you don’t, just set the camera as a child of the player). A and D would translate/straffe the character, not rotate the camera, in classic DOOM.

Maybe you’re thinking of “Tank Controls”

Solved it by messing with standard vectors in transform.rotate. Thanks for the answers though!