My History of Game Programming (Part 5 – Unity/C#)

My third project using Unity© software is an isometric RTS game with 2D sprites and 3D environments. My friend and I did quite a bit on this project before progress was halted. We added a GUI with weapon selection, placing barricades, showing weapon range arcs, over watching directions, toggle the grid, explosives, selection box, camera angle rotation change, camera zoom and squad formations. The level that is shown in the GIF below is a wave based game mode where enemies come from four directions and you fortify the center to try and complete all the enemy waves.

The sprites displayed in this are from the game Doom and we were using them just for internal testing.

GIF

One feature of the project is the ability to rotate the camera which was a small challenge using 2D sprites. I decided not use the animation system and instead wrote my own sprite sheet drawing. When the camera is rotated the sprites draw based on what angle you are looking at them and where they are looking at. For example if the camera is behind an enemy that is looking the opposite direction, then the game needs to be drawing his back side. This requires the sprite sheets to have frames for every 45 degrees of the object. To accomplish this I find the angle of a line given the two points, the object and the camera, and then add the objects look angle. This determines in what angle I need to draw the sprite. The code below is a snippet of how it works.

    angleBtwCamPlayer = FindAngleBetweenThisAndCamera() + transform.parent.gameObject.transform.Find("EnemyLook").transform.localRotation.eulerAngles.y;
    //Then we use the angleBtwCamPlayer to set show the right sprites. 
    if (angleBtwCamPlayer <= 22.5 || angleBtwCamPlayer > 337.5)
    {
        CameraFacingFront();
    }
    //camera is facing in front and right of player
    else if (angleBtwCamPlayer > 22.5 && angleBtwCamPlayer <= 67.5)
    {
        CameraFacingBackRight();
    }
    //so on and so forth for the rest of the directions

    float FindAngleBetweenThisAndCamera()
    {
        //get your current position and the camera position
        Vector2 yourPosition = new Vector2(transform.parent.transform.position.x, transform.parent.transform.position.z); 
        Vector2 cameraPosition = new Vector2(cameraGO.transform.position.x, cameraGO.transform.position.z);
       
        float deltaY = cameraPosition.y - yourPosition.y;
        float deltaX = cameraPosition.x - yourPosition.x;
        float ang = Mathf.Atan2(deltaY, deltaX) * 180 / Mathf.PI;
        ang = ang + 90;

        if (ang < 0)
            ang += 360;
        else if (ang > 360)
            ang -= 360;

        return ang;
    }

The below gif is the drawing in action.

GIF

Further Thoughts

For the movement I used a simple implementation of a*. The grid is updated when each object spawns or moves and if they move then they will update their new grid position and their last with the changes.

Looking back at it now, as a wave based defense game, it is almost complete code wise. It has almost no assets though which is the part I have most trouble with games. I am good at making features work but producing art and other assets is defiantly not my strong suite. I feel I would excel in a team where I could be fed assets to put into the game and code their functionality.