- Home /
Lerp incomplete movement problem
Hey guys, I'm working on a project where the player toggles movement directions with the keyboard, and their controllable character moves in fixed increments, as if in a grid. Each 'grid tile' is to be 1x1.
I've read the GridMove script on the Wiki site, but it's not compatible with with the movement limitations the game mechanics will employ. As a result, I've used Vector3.lerp to create a simpler version, but I need the player to move uninterupted, wheras the movement stops once the player is no longer holding down the key. I need it to move 1 'unit' along the X axis (other directions can come later) when the button is pressed. It is critical that the player only moves one whole number at a time. If anybody can help me figure out what I'm doing wrong, it'd save me further headache!
here's what I've stripped my previous system down to:
var startPosition : Vector3; var endPosition : Vector3;
function Start () {
}
function Update () { var myTransform = transform;
startPosition = myTransform.position;
//Detect left or right movement
horizontalMovement = Input.GetAxis("Horizontal");
//Detect up or down movement
verticalMovement = Input.GetAxis("Vertical");
if (horizontalMovement > 0 ){
MoveRight();
}
}
function MoveRight () { var myTransform = transform; var t : float; //print("East");
endPosition = Vector3(myTransform.position.x+1.0,myTransform.position.y, Time.deltaTime);
myTransform.position = Vector3.Lerp(startPosition, endPosition, Time.deltaTime);
}
Cheers, - Stew
I have my suspicions that this has something to do with the lack of a 'Yield' command.
Answer by Ozale · Mar 08, 2011 at 10:04 PM
I've fixed it. I needed to dynamically create the start and end position a different way, structured so that it will finish any current movement.
Your answer
