Keeping forward transform

Hello,

I have a movement script that I am using to rotate a character. Whenever I release the rotation the character snaps back to it’s original facing position. Does anybody know how to keep him facing the last direction?

Here is my script that I am using.

			//Rotation
			float x = Input.GetAxisRaw("Hor");
			float y = Input.GetAxisRaw("Ver");


			transform.forward = new Vector3(x, 0, y);//I want to keep this rotation after releasing, now it just snaps back to original.
        }

My rotation works perfectly, so if you use my script template, it ought to work for you as well.

This script requires a character controller to be attached to the same gameObject.

var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var rotateSpeed : float = 3.0;

private var moveDirection : Vector3 = Vector3.zero;

function Start ()
{
	//Any animation that you want it to start on goes here
}

function Update ()
{
	var controller : CharacterController = GetComponent(CharacterController);
	
	//Animation code here
	
	if (controller.isGrounded)
	{
		//Movement code here
		
		//Rotation Code
		transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
		
		moveDirection = transform.TransformDirection(moveDirection);
		moveDirection *= speed;
		
		//Jumping code here
	}
	
	//Gravity code here
	
	//Move Controller
	controller.Move(moveDirection * Time.deltaTime);
}

i would recomend using transform.Rotate it would look like this:

 float x = Input.GetAxisRaw("Hor");
 float y = Input.GetAxisRaw("Ver");
 float speed = 5f;

//the Time.deltaTime makes sure it is framerate independent
transform.Rotate(x, y, 0, speed*Time.deltaTime);