- Home /
Tweening is not consistent
Im new to tweening, so I may just be missing something simple in this scenario.
I need to move my camera a fixed distance over a fixed amount of time, depening on what key is pressed. I've tried to accomplish this with both iTween and LeanTween, with the same wonky results, so the issue has to be my code. It's working mostly as intended, but half of the time the tweening does not take place - my camera immediately snaps to the new location. Below is my update method and one of my movement methods. Should tweening be handled in Update or FixedUpdate?
Video to show problem: http://www.youtube.com/watch?v=dZcgapCyDOU
void Update ()
{
if(firstrun)
{
playerMarker = explorationCameraController.explorationCamera.transform.position;
firstrun = false;
}
if(explorationCameraController.explorationCamera.transform.position == playerMarker)
{
if(Input.GetButtonDown("Forward"))
{
MoveForward(explorationCameraController.CurrentDirection);
}
if(Input.GetButtonDown("TurnRight"))
{
TurnRight(explorationCameraController.CurrentDirection);
}
if(Input.GetButtonDown("TurnLeft"))
{
TurnLeft(explorationCameraController.CurrentDirection);
}
if(Input.GetButtonDown("Backward"))
{
MoveBackward(explorationCameraController.CurrentDirection);
}
if(Input.GetButtonDown("StepLeft"))
{
StepLeft(explorationCameraController.CurrentDirection);
}
if(Input.GetButtonDown("StepRight"))
{
StepRight(explorationCameraController.CurrentDirection);
}
}
}
public void MoveForward(string CurrentDirection)
{
switch (CurrentDirection.ToLower())
{
case "up":
default:
{
Vector3 direction = new Vector3(0,0,1);
if(!isWall(direction))
{
playerMarker = explorationCameraController.explorationCamera.transform.position += direction;
LeanTween.move(explorationCameraController.explorationCamera, playerMarker, moveSpeed);
//iTween.MoveTo(explorationCameraController.explorationCamera, new Hashtable(){{"position", playerMarker},{"time", moveSpeed}});
}
break;
}
case "right":
{
Vector3 direction = new Vector3(1,0,0);
if(!isWall(direction))
{
playerMarker = explorationCameraController.explorationCamera.transform.position += direction;
LeanTween.move(explorationCameraController.explorationCamera, playerMarker, moveSpeed);
}
break;
}
case "down":
{
Vector3 direction = new Vector3(0,0,-1);
if(!isWall(direction))
{
playerMarker = explorationCameraController.explorationCamera.transform.position += direction;
LeanTween.move(explorationCameraController.explorationCamera, playerMarker, moveSpeed);
}
break;
}
case "left":
{
Vector3 direction = new Vector3(-1,0,0);
if(!isWall(direction))
{
playerMarker = explorationCameraController.explorationCamera.transform.position += direction;
LeanTween.move(explorationCameraController.explorationCamera, playerMarker, moveSpeed);
}
break;
}
}
}
Comment