Lerp rotation question

I am trying to code up a simple first person grid movement system. The plan is for it to only receive input for movement if the player is aligned to the grid (I do this by checking via mod to see if there is no remainder).

That part works. But the movement, I can’t seem to get to work… And I know it is because I have done the movement wrong.

Here is my script

var gridSize : int = 4;
var moveSpeed : float = 4.0;
var canMove : boolean = false;

function Update() 
{

		var currentRotation = transform.rotation.y; //get current rotation along y axis
		var currentX = transform.position.x; //get current x position
		var currentZ = transform.position.z; //get current z position
		
		//check if aligned to grid and not in middle of a rotation.
		if (currentX % gridSize == 0  currentZ % gridSize == 0  currentRotation % 90 == 0) canMove = true;
		else canMove = false;
		//Debug.Log ("Player is aligned : " + canMove);
		if (canMove)
		{
			if (Input.GetAxis("Vertical") > 0)
			{	
				Debug.Log("Moving Forward");
				MoveForward();
			}
			else if (Input.GetAxis("Horizontal") > 0)
			{
				Debug.Log("Turning Right");
				TurnRight();
			}
			else if (Input.GetAxis("Horizontal") < 0)
			{
				Debug.Log("Turning Left");	
				TurnLeft();
			}
		}
}

function MoveForward()
{
	var originalPosition = transform.position.x;
	var newPosition = transform.position.x + 4.0;
	transform.position.x = Mathf.Lerp(originalPosition, newPosition, Time.deltaTime * moveSpeed);
}

function TurnRight()
{	
	transform.rotation.y = Mathf.Lerp(transform.rotation.y, transform.rotation.y + 90, Time.time);
}

function TurnLeft()
{
	transform.rotation.y = Mathf.Lerp(transform.rotation.y, transform.rotation.y - 90, Time.time);
}

What is wrong with the MoveForward, TurnRight and TurnLeft - the scriptingreference doesn’t seem to give much advice on Lerps.
Thanks!

Lerp doesn’t “do things over time”, it’s a very simple math function that returns a value once, immediately. In order to animate with it, you have to call it repeatedly with values increasing from 0 to 1. Time.time as the 3rd variable will do nothing, it’s always past 1 aside from the first second of play. Also, Transform.rotation is a 4-dimensional quaternion, and the y component is not the y axis. http://www.unifycommunity.com/wiki/index.php?title=MoveObject

–Eric

Cheers, I knew I had the lerp stuff wrong. I actually found another thread you posted in and gave some advice on a similar topic

http://forum.unity3d.com/threads/46754-First-Person-Grid-Based-Movement

so I’m reading through that. There is code in there that works, but I don’t like the idea of copying and pasting without understanding, so I’m gonna take a look and see how the Lerp works in there and implement something similar in my script above!

Thanks so much for your reply!