Making the map more real
So I have a map that renders, but that’s no fun. Next, I wanted to be able to have a character that can move through the map and actually be blocked by walls etc. This was fairly simple but required me to learn about Unity’s new Input System. In all my other projects, I had just coded input listeners in directly, into a code called InputManager.cs.
It was fairly easy to learn the Input System and I still ended up needing an InputManager.cs file to handle all the input and shunt it to the proper code. I’m 90% sure I’m not using it super effectively, but at this point I don’t care. I’ll let future me worry about that when I eventually get around to user options like changing keymapping. I’m pretty sure I at least have the basics set up for that to work well down the road.
Input was pretty easy to get working, so next I needed to make the user be blocked by walls. This is where my custom LOS_Mapcell class came in handy. One of the properties of the class was a float called “passability”. It tells the game how time consuming it is to walk into that cell. If the cell has a passability of 0, the user can’t walk into it at all. A single Mapcell can actually hold several objects (ground, ground covering, furniture, and items) and if ANY of those have a passability of 0, the player can’t enter the cell. Simple as that.
I also wanted to restrict the player’s line of sight. This turned out to be pretty easy. Remember in an earlier post I talked about beg, borrow, steal. Line of sight for a grid based thing has been neatly solved by something called the Bresenham Line Algorithm. It was pretty easy to find a piece of code written in C# that I could drop into my game and use. Granted, whoever coded it was waaaay more efficient with code than I would have been, so I don’t understand what they did super well, but I do understand the algorithm, so I was ok with using it. It wasn’t long before I had a character who could walk around a room, bumping into things and having line of sight!



