Alright so i am trying to write a movement script kind of like what would be used for a 2d side scroller. my problem lies in having the character rotate to the direction he is walking. i cant seem to figure out a solution to make this work properly. here is the current code i have atm
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
public float speed = 10.0f;
public float rotationspeed = 100.0f;
private float moveBack = -1.0f;
private float moveForward = 1.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if(Input.GetKey(KeyCode.A))
{
float translation = moveBack * speed;
//float rotation = moveBack * rotationspeed;
translation *= Time.deltaTime;
//rotation *= Time.deltaTime;
transform.position += Vector3.right * translation;
}
if(Input.GetKey(KeyCode.D))
{
float translation = moveForward * speed;
//float rotation = moveBack * rotationspeed;
translation *= Time.deltaTime;
//rotation *= Time.deltaTime;
transform.position += Vector3.right * translation;
}
}
}