Two Weeks In

I just finished up my second week of part-time paying job, part-time building a game and the change is amazing. Gone are the days of laying in bed Sunday mornings and stressing about work, or trying to come up with a solution to a work related problem. With only three days of the week at the paying job, the majority of my week is no longer spent at the office. My random thoughts are now shifted to FromTheFord.

At this point I’ve already settled into a new typical weekly schedule.
Saturday is my day to relax, clean, and maybe work on the game if I feel like it.
Sunday is kind of like a half day. My goal is to put at least a few hours in, but I don’t stress if I have plans for the day and don’t find any time to work on the game.
Monday and Tuesday are game work days. I treat them just like regular work days.. I wake up early, get ready for the day, and get to “work” before 9am. The only difference is I’m spending 8 hours at home working on the game instead of going into an office.
Wednesday through Friday are regular work days.
Evenings throughout the week I will work on the game if I’m motivated, but I no longer try to force myself to after a stressful day at work.

One important change that I’ve made is creating a dedicated space that functions as my work area. Previously my desk was in my bedroom. My bed was on one side of me, the door into my bathroom on the other. It was kind of dark, carpeted and I never felt very productive there.
Now I’ve rearranged my dining room and have my desk in one corner of it. The area is more open, has plenty of natural light, laminate wood flooring, and is no where near my bed or my bathroom. It feels more like a work setting and I believe that has helped me be more productive.

I’m starting to make good progress on the game, and along the way I’ve learned quite a bit. My plan is to start sharing some of my progress as well as writing up some tutorials on the things that I’m learning. My first attempt at a post about how I am implemented saving/loading of game data made me realize how much time creating a good tutorial can take. That post will have to wait for another day. For now I’m going to share some simple changes I made to the games camera system.

The camera I built for the game has a large number of settings that can be tweaked. This allows us to play around with how the camera works without having to change code and recompile the game. While switching the game over to 3d terrain I started playing around with the angle of the camera. This lead me to an issue with how the camera was programmed.

One important thing to note is that the camera is contained within another gameobject. In game when the camera is rotated or panned the camera container is updated, but the camera itself stays at the same local position. Camera rotation is handled by rotating this container around the y axis.
Originally the camera had a height above the surface, a z position, and an angle. The problem with having those three settings is that if you change the angle, you then need to find the correct z position to make sure that the center of the camera view is pointing at the place where the y axis of the camera container intersects the terrain. If the camera view was not centered on that point, then when you rotate it the view would swing in a very disconcerting manner. The world view would be rotating around a point that was not in the center of the players screen.

The solution to this was pretty obvious once I decided to spend the time to correct it. The only two settings that are required now are the distance the camera is from the center of the game screen, and the angle that it is rotated at. The blue and red lines in this image.

Using trigonometry – given an acute angle and the hypotenuse of a right angle, you can find the opposite and adjacent lengths of the triangle.
In this case, the camera distance is the hypotenuse. This means we can calculate the camera height (opposite side) using Sin.
Then the depth (z position) can be calculated using the Pythagorean theorem. It could have also been calculated using Cos.

    var height = Mathf.Sin(Mathf.Deg2Rad * this.Angle) * this.Distance;
    var depth = Mathf.Sqrt((this.Distance * this.Distance) - (height * height));

    this.cameraGameObject.transform.localPosition = new Vector3(0, height, -depth);
    this.cameraGameObject.transform.localRotation = Quaternion.Euler(this.Angle, 0, 0);

With this change it is now simple to adjust the camera angle. No more messing around with multiple settings trying to get the camera to rotate properly.

Leave a Reply

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