Sunday 11 May 2014

Coding - Camera and Controller


Obviously for a third person platformer you need a controller and a camera that does what you need it to do. To start with we wanted the controller to walk around and jump in a way in which you could edit the distances it could jump and make the controls feel smooth. for the camera you want to be able to rotate it yourself, but also for it to follow the character in a natural way.

This was not easy, not at all. I debated with myself whether to take what was already in Unity on code some of my own things. I decided that I did not want to take what was default with unity, partly because I just didn't like it.

For both the controller and the camera, I tried many different things, my own code, code online and more, however there were always bugs, or code that interfered with each other. at that point I did not understand why. I ended up with commented out code all over my scripts, keeping in what worked and trying new things. One time I scrapped and restarted the controller completely.

Early Scripts on Disk

I then realized that I really needed to get a grasp on what some of the code I was copying was and what it did, so I went through the basic scripting tutorials on the unity website, and from that I became equipped with what I needed to know.

I decided to take what I liked from the scripts that are provided with unity, and then code changes to them myself. I did this with the main camera, and achieved a very nice result from it. It took a while but was worth it.

For the character controller I took the default ground movement script, and then looked at other code people have created for jumping, and used one of them to create my own jumping script.

Ealry Scene on disc

The result was a character controller with a few bugs, but much better than before, and a camera script which followed the character smoothly and well, which the player could also influence. I was also left with one document full of commented out script that I decided to keep for reference.

Final Scripts on disc.

When I got to this point I realized that I had leaned a lot, and had a result that was by far better than Unity's default. It was at this point I got a bit confidence boost and realized that I could code a lot for this game.

No comments:

Post a Comment