Rotation and movement?

Hey guys. I’m still learning Unity, using JavaScript. I’m trying to make a character that you rotate with the left, and right, arrow keys, and then you press up, and he moves forward. I kind of have it working, but not quite. The problem is, once you rotate around so much, then the character starts moving in a different direction, than he is facing. I don’t really know how to explain it better than that, other than the direction he is moving, and the direction he is facing, is not matching up. Here’s the code

#pragma strict
var walkSpeed : int;
var runSpeed : int;
var turnSpeed : int;

function Update ()
{
if (Input.GetKey(KeyCode.LeftArrow)) {
    transform.Rotate(0,-turnSpeed  * Time.deltaTime * turnSpeed,0);
}

if (Input.GetKey(KeyCode.RightArrow)) {
    transform.Rotate(0,turnSpeed  * Time.deltaTime * turnSpeed,0);
}

var direction = transform.forward * Time.deltaTime * walkSpeed;
if (Input.GetKey(KeyCode.UpArrow)) {
    transform.Translate(direction);
}
}

I’ve even tried removing the “* Time.deltaTime * turnSpeed” But it’s just the same result. Any help would be appreciated.

I am not sure whether i have correctly understood you question, but you can try this.

Replace the movement code as follows:

if (Input.GetKey(KeyCode.UpArrow)) {
transform.position += transform.forward * Time.deltaTime * walkSpeed;
}

Do let me know if it solved the issue.