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);
}
}