Reputation: 13
I'm learning about how to make games in Unity and I've already ventured into 2D games and now I wanted a 3D one to continue studying. I'm wanting to make a board game, but the tutorials only show how to make it work, but none show how to animate the movement, I don't want it to simply be taken from point A --> B, I want it to do as in the game Incryption, in that the pawn jumps as if it were jumping tile by tile. How can I do this?
I tried to use animation combined with Vector3.Lerp, but the animation makes the pawn always stay in the position it was animated. One solution that seemed to work was to not use animation and use Vector3.Slerp. But I wanted the movement to be like in the game Inscryption, where he jumps until he reaches the right tile.
Upvotes: 0
Views: 79
Reputation: 13
It worked perfectly, my code looked like this:
public void MoveNext(int numMoves)
{
if (!isMoving)
{
isMoving = true;
targetPos = allTiles[(currentTileIndex + 1) % allTiles.Length].position;
float distance = Vector3.Distance(transform.position, targetPos);
int jumps = Mathf.RoundToInt(distance / 2.5f);
DOTween.Sequence()
.Append(transform.DOJump(targetPos + new Vector3(0f, 0.5f, 0f), jumpHeight, jumps, distance / 5).SetEase(Ease.Linear))
.Append(transform.DOMove(targetPos + new Vector3(0f, 0.5f, 0f), timeToMoving).SetEase(Ease.Linear))
.OnComplete(() =>
{
isMoving = false;
currentTileIndex = (currentTileIndex + 1) % allTiles.Length;
currentTile = allTiles[currentTileIndex];
});
}
}
Upvotes: 1