Skill Tree Activated

The quest to become an indie game developer

#100DaysOfCode#100DaysOfGameDevC#Illogical BaconPanic RoomScript-writingUnityVisual Studio

Coming Full-Circle

#PanicRoom Day 079

#100DaysOfGameDev R2D44
#100DaysOfCode R2D44

changelog

Today started with the initial placement of the side exterior walls. I knew there was going to be some tweaking involved but wouldn’t know to what extent until I got something placed. Because of the new approach I was taking with HouseBuilder (which was making things so much more easier!) it didn’t take me too long to parse my previously-written code and make some quick changes. There were actually big sections I could cut out due to the new 1×4 tile format because I didn’t have to account for odd lengths or tight fits.

side exterior walls misaligned

Once I had my initial result from the new code I could see that my vertical walls were starting in the right spot, if only appearing over the top of the bottom horizontal walls, but not quite going all the way up to the top wall. When I looked into what was causing this it became clear fairly quickly: I needed to adjust my sprites/prefabs for the vertical wall tile.

horizontal wall tile box collider (which is the bottom surface that contacts the ground)

My redesign of the wall structure brought me to an essentially easier to use 1×1 wall piece format. Due to the nature of my 3/4 view 2D perspective, my horizontal wall tiles have a 1×1 top surface on top of a column that is 3 tiles high. To convey the proper sense of perspective I needed to designate a bottom 1×1 tile to represent the surface of the wall that actually makes contact with the ground. This is also the only part of the wall I should be considering for both placement and collision purposes, as multiple sections of wall placed next to each other on any side will all butt up against each other based on this same 1×1 floor section.

vertical wall box collider (which shows where contact with the ground would occur)

This is all relatively clear on the pieces of horizontal wall, but on the vertical walls I am only showing the top surface because in the 3/4 perspective the front surfaces of the walls will be occluded by the each piece of vertical wall or by a horizontal wall in front. Of course if I ever have a free-standing vertical wall I will need to show this front surface, but that is not a concern right now when building the box that is the enclosure of the house’s exterior walls.

side exterior walls in alignment

To get my vertical wall pieces into the correct positions using the row and column grid system I have established, I needed to adjust the sprite so the base of the wall will be implied during wall placement. This was a simple matter of extending the length of the overall sprite to the 1×4 format and making the box collider the same as if it were a horizontal wall piece, which is represented by that 1×1 bottom surface. Altering my vertical wall sprite in this manner brought all the calculations for the house into perfect harmony with the desired perspective and yielded exterior walls that all line up and touch properly.

With enclosed exterior walls once again, I wanted to test my mesh collider formed by the walls against the player character to make sure there were no weird hidden seams that could be slipped through and everything was tight. I’m glad I tested.

player cut off by horizontal walls
player clipping into vertical walls

While the colliders were holding up, I did discover I wasn’t happy with the level of clipping that was going on when the character got near the side and top walls. This wouldn’t do at all!

In these cases there was actually two different things going on. The side walls issues was true clipping from the character getting too close and the images overlapping when the player’s arm actually shouldn’t be able to penetrate the wall. The top wall issue was from sorting order layering that was off, which was the easiest to fix.

all sorting layer orders equalized

All my wall tiles, both vertical and horizontal, as well as my player character are all on the same sorting layer (default). When I was working with my last building system version I guess I had to play around with things to get them to come out right because I discovered these three different assets were all set to different order numbers on the layer, which was causing the horizontal wall to overlap the player even though the player had a lower Y value. Once I set each wall piece and the player all to the same order number on the sorting layer they all started displaying properly.

player cannot enter wall now

To combat the side wall clipping issue I decided to re-do the collider for the player character. I initially wanted to keep the collision area limited to the actual footprint area of the character and, as such, utilized a circle collider just big enough to cover the ground around his feet. While it worked for collision, it had the unfortunate side effect of the clipping I was now dealing with from the player being able to get too close to the walls. I removed the circle collider and instead put in a box collider. I made the actual collider big enough to cover a ground space of the entire character, not just the fit. This meant it was large enough to cover an area that would encompass not only the feet and legs, but also the arms and shoulders. This successfully kept the player far enough away from the walls that he couldn’t clip and it still looked like a natural physical barrier. Problem solved!

testing vertical primary hallway placement

Since I was on such a roll this morning I kept things going and started work on the Primary Hallways again. My intent was to give myself an idea of where I would be jumping off from tomorrow and just wanted to see what was going on with my code as it stood. I reactivated the hallway-building block of code and was actually surprised it wasn’t too far off the mark. My hallway width was a little off, being half a grid square short of what I wanted, but some quick tweaking of a couple of lines had that taken care of in no time and the hallways build themselves quite nicely. And the best part? Where my code says the hallway is now matches where the grid overlay says the hallway is! This is what started the need for the whole codebase redesign in the first place, so here I am full-circle.

Leave a Reply

Your email address will not be published. Required fields are marked *