Im trying to get the player to move from tile to tile and i got that to work already with this code. The problem is that is jumps right to the spot and i want to go there at my speed. How its set up now it goes off the x first and then goes off z, so it follows the grid of the game and doesn’t just go straight through the grid.
public class Controller : MonoBehaviour
{
public GameObject selectedPawn;
public Color inRange;
public Color outRange;
public float range;
public float speed;
public bool selected;
private bool standing;
private bool attacking;
public bool moving;
private bool showAttackMenu;
public bool showFacing;
private GameObject[] tiles;
void Start()
{
moving = false;
standing = true;
attacking = false;
tiles = GameObject.FindGameObjectsWithTag("Tile");
}
public void SetSelectedPawn(GameObject pawn)
{
selectedPawn = pawn;
}
/*public void Move(GameObject targetTile)
{
StartCoroutine("MoveX", targetTile);
}*/
public void Move(GameObject targetTile)
{
if (!moving)
{
selectedPawn.GetComponent<SelectPawn>().ChangeAnim(2);
//print(moving + "2");
moving = true;
float travelTimeOne = targetTile.transform.position.x - selectedPawn.transform.transform.position.x;
float travelTimeTwo = targetTile.transform.position.z - selectedPawn.transform.transform.position.z;
selectedPawn.transform.Translate(travelTimeOne,0,0,Space.World);
selectedPawn.transform.Translate(0, 0, travelTimeTwo, Space.World);
/* iTween.MoveBy(selectedPawn, iTween.Hash("x", targetTile.transform.position.x - selectedPawn.transform.position.x,
"easetype", "linear", "time", travelTimeOne));
iTween.MoveBy(selectedPawn, iTween.Hash("z", targetTile.transform.position.z - selectedPawn.transform.position.z,
"time", travelTimeTwo, "delay", travelTimeOne, "easetype", "linear"));*/
DoneMoving();
CheckTiles(2);
//selectedPawn.SendMessage("DoneMoving");
moving = false;
selectedPawn.GetComponent<SelectPawn>().ChangeAnim(1);
}
}