I have seen many other questions on this but none seem to work. I was using transform.Translate but that meant when I rotated forwards became a different place and so it would just stop.
My code:
using UnityEngine;
using System.Collections;
public class Movement2 : MonoBehaviour {
//Inspector Variables
float playerSpeed = 0.05f; //speed player moves
void Update (){
UpAndDown();
RightAndLeft();
}
void UpAndDown (){
if(Input.GetKey("up"))
{
//transform.Translate(0,playerSpeed,0); this is the old system
transform.position = new Vector3(transform.position.x, transform.position.y + playerSpeed);
}
if(Input.GetKey("down"))
{
transform.position = new Vector3(transform.position.x, transform.position.y - playerSpeed);
}
}
void RightAndLeft (){
if(Input.GetKey("right"))
{
transform.position = new Vector3(transform.position.x + playerSpeed, transform.position.y);
}
if(Input.GetKey("left"))
{
transform.position = new Vector3(transform.position.x - playerSpeed, transform.position.y);
}
}
}