Donut's Thoughts

Submarine Shreddin' Postmortem (2/2)

This is the first half of an postmortem I released for a game I made for the 2018 LOWREZJAM. I'm sharing it here to have it both in a place where I plan to keep all of my writing in, as well as a backup. Enjoy!

Imgur Imgur
Imgur

So, Submarine Shreddin’ was fun to make (you can play the game jam game over here!) but the more fascinating problem I had to solve for the game was trying to achieve collision for a flat surface - and also make it look the part.

Above is the simple setup I ended up with, with a little snippet of what the Driver GameObject hierarchy looks like.
Imgur

After going through hell and high water trying to get Unity’s axis orientations to work nicely with both the camera and the plane for the track, I ended up with this weird solution - I ended up with three layers of planes, being the track’s actual graphics, a “heat map” of the track used and a collision check for the track.
Imgur

“RacingTrack” is only for display purposes, with only a Sprite Renderer attached. “TrackRef” is the more interesting of the two - while its Sprite Renderer is turned off, it contains a color map of the same racing track - with each color designated to either the road, grass or dirt. The latter two are specifically for slowing down the driver, but I decided to remove this close to finishing. The original reason for making this was to add a F-Zero-like charge pad system to the track, but that got dumped as well over time.

Lastly, “CollisionCheck” is where the GameObjects meet the code. Essentially, this object contains a plane (with its Mesh Renderer turned off) which I use as essentially a coordinate pointer with some raycasting. This then crosschecks with an array of the colors listed before, and that is what I use to modify player values, which is a whole other thing. You can find a short bit of the code used in this portion of the project below:

void Update () {
        Ray terrainCheck = new Ray(transform.position, transform.forward);
        RaycastHit terrCheck;

        if (Physics.Raycast (terrainCheck, out terrCheck, 20f)) {
            currTerrain = trackPixels.GetPixelBilinear (terrCheck.textureCoord2.x, terrCheck.textureCoord2.y);
            for (int i = 0; i < terrainTypeList.Length; i++) {
                if (terrainTypeList [i].terrainCol == currTerrain) {
                    GetComponent<RacerMove> ().currTerrain = terrainTypeList [i];
                }
            }
        }
    }

#game dev