For those that aren’t following my facebook page I have decided to start posting my developer diary to arsoftware.co.uk as well.
Ok, day 12. Today was a big day for development. After day 11’s complete failure to work out why my door trigger zone wasn’t working I sat down to work out why. Seems like something very simple that just wasn’t working. Player walks near door, door opens. Except it wasn’t.
After quite a bit of time looking in to it I finally realised my mistake. In normal programming conventions it is customary to use camel case for variables etc, so, each word in the variable name has a capital letter except the first, e.g. thisIsAVariableName. Now for some odd reason Unity 3d abandons this for function names, so there I was using onTriggerEnter when it should have been OnTriggerEnter. You can see why it took so long to notice this glitch.
With my triggers now working I set about creating the games first piece of code, a door control. My original test door used animations to open and close the door, the problem with this is a lack of flexibility. The door will always open in one direction, unless I make further animations for opening in the other direction. So, I wanted to write a script to swing the door depending on where the player was – to avoid the door swinging in the players face. It took a bit of doing but with a liberal dose of euler angles I now have my first programmed door that swings open away from the player, can start slightly open if necessary, and will close (if required) after the player walks away from the door.