top of page

Real-time Progremmatic Animations

  • Writer: Sage Dupuy
    Sage Dupuy
  • Apr 22, 2020
  • 3 min read

Updated: Apr 24, 2020

Real-time Programmatic Animations is just a fancy way of saying doing stuff in code that looks like it would be animated. In reality most animations are technically made with programming. Like with particle effects; those are generated based on parameters passed into a system that reacts differently depending on the values of those parameters. I experimented with this sort of thing ages ago when I was first getting into Unity. It was a remastering of a game I made while at a camp for Digi-Pen. That in itself was a poor attempt of a copy from another game on itch.io called Three Body Problem by roBurky. It was quite basic; you were a circle trying to touch purple squares and avoid the orange squares. The orange squares had artificial intelligence to move around and go after you. The main thing is that the A.I. was so great! They would slow down, speed up and bounce in different directions depending on a bunch of variables. I wanted to make that and try to recreate the A.I..

Since the camp I was in was an artificial Intelligence camp it was the perfect fit and I was able to create it rather effectively. It worked, people rage quit a bunch cause it was so OP and it was genuinely a fun game to try to win at. I called it Unlucky, Seriously Unfortunate Combination or U.S.U.C. for short. When that camp was over and I got into Unity I wanted to expand on that fun game. After making the rough basics I had a ton of ideas for it. I started working on the arena that the game would take place in. I wanted it to be a cool loading visual as the game was gonna have a bunch of assets. It was gonna be a spiral of hexagons that formed the ground and the walls for the game. The only thing that was difficult at first was getting the objects to be created sequentially as the game got it's assets loaded. I was able to do it in the end and learned a bunch of nifty tricks about that kind of thing. Here's what it looks like now.

With just a little bit of randomization for the height of each of the objects it looks rather good, right? Behind the scenes it's actually a very simple program.

This is the main snippet that does everything.

switch(side)
{
    case 1:
    case 2:
    case 3:
    case 4:
        CreateSideFloorObjects(side);
        break;
    case 5:
        //Left
        bool IsOnLayerBeforeLast = layer == totalRadius - 1 && layerRepetitionCount == layer;
        if (IsOnLayerBeforeLast)
        {
            spawnPos.y += 0.75f;
            isWall = true;
        }
        if (layerRepetitionCount < layer + 1)
        {
            CreateFloorObjectAt(hexagonalDirections.Left);

            if (layer == totalRadius && layerRepetitionCount == layer) side = 0;
        }
        else
        {
            GoToNextSide();
        }
        break;
    case 6:
        //left, up
        if (layerRepetitionCount < layer)
        {
            CreateFloorObjectAt(hexagonalDirections.TopLeft);
        }
        else
        {
            GoToNextLayer();
        }
        break;
    default:
        Destroy(GetComponent<FloorSpawner>());
        break;
}

Also here's what the terminology of this code is referring to.

Since we want the hexagonal spiral to make an object 1 at a time to give it the affect that it's spiraling we need for the script to only make 1 object each frame. So this is exactly what it does, only it splits it up a little to make the whole spiral. Since there are 6 sides to a hexagon we have a number that tells us what side we're on. Then we call a function that creates the floor objects on that side specifically. Only on 5 and 6 do we need to do something special.

On side 5 we have to ask if we are on the layer before the last and then if we are set the boolean is wall to true and increasing the y of the spawn position to move the floor objects up so they become the walls.

On side 6 we do the same as any other side except instead of going to the next slide we increase the layer we're on.

There are some more code specific things like the sideRepititionCount, and some novelties about switch statements. This is as much as you need to know if you're not a programmer. This was a little bit of a test to see if I could describe something like this to a non coder. If you have any questions or were confused let me know on what so I can improve. Thanks in advance.

 
 
 

Comments


bottom of page