Home > other >  How can I make a "jump between tiles" animation for a boardgame?
How can I make a "jump between tiles" animation for a boardgame?

Time:01-12

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?

Inscryption Map

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.

CodePudding user response:

The best way to do that would be to use a tween library, for example DOTween. You can tween your object to move to the new tile, or to jump to the new tile (dotween has a nice DOJump tween and DOMove tween).

CodePudding user response:

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];
            });

    }
}
  • Related