So for the first post for the Patreon, I thought it would be cool to share a funny story that happened while adding in a feature for the game. I'll attach a video so you can see what was happening. I still have to figure out how to use Patreon a bit, so idk if the way I added the video is the best way. I couldn't find an option to embed the video or anything. In the video, the red sphere you'll see is supposed to be the player.
While working on one of the levels in the game, Rodrigo thought it would be cool to have the NPCs look at the player if they get close to them, and he asked me if I could add the feature. I told him it was really easy because I knew that in Unity there's a line of code that does exactly that: Transform.LookAt();. But it turned out it wasn't that easy. Using this line of code made the side of his head start looking at the player. Apparently the XYZ axes for the NPC model were in the wrong orientation, causing the forward direction of the head to not be where his face is.
What I did to fix this was track the player's position, figure out the distance to the NPC's head, and then make an invisible sphere move an equal distance, but at a right angle between the player and the NPC's head. Then I made it so that he "looks" at the sphere to his right, but technically it fixes the error I had with the axes and makes him look at the player...
...Except only when he is at eye level with the NPC. Moving above or below the NPC's eye level turned him into a contortionist. It took me a while to figure out what I did wrong this time, and I ended up trying to add in a bunch of different invisible spheres, lining up different axes, all in an attempt to see what was causing the problem. I was trying to remember some dumb trigonometry formulas from high school, and it seemed like nothing was working. This was driving me crazy for hours until I realized I that I wrote the wrong value in one of the lines of code, causing him to double correct for the axes being wrong. Sometimes I really hate programming lol