It's been a while since I last posted so before I get in to the topic of this post I'll mention what I've been up to as it has some relevance.
I have been working on adding network game play. It did not take me long to realise that the way I originally did the physics in the game, that works for single player and split screen, does not work for a network client server based game!
My mistakes were that I used variable time step with a lot of relatively simple maths to ensure all movement was smooth and I used a single state for working out what the character was doing. I have now learnt that I need to keep a history of the movement and states of the entities and use the state at a point in time to best approximate where all the characters are in relation to each other and what they were doing at that same point in the past.
I have nearly finished making those changes so at least the single player game works with a history of states. In the process I changed the way the movement physics was calculated. Probably not essential but I came across better ways of doing things while I was looking in to networked physics.
I ended up using more quaternions than I had previously. I still convert to matrices in several places to get some results but where possible I have tried to leave the quaternions as quaternions and use quaternion maths to get the results. Just in case it was not obvious, I am not very familiar with quaternion maths. I think I now get it but basically I look up formulae on the Internet and convert them to C# code to get the results I need.
/// Returns the forward vector from a quaternion orientation.
/// Returns the up vector from a quaternion orientation.
/// Returns the right vector from a quaternion orientation.
I am sure any professional developers will understand the importance of testing. I may not be a professional but from experience I know I cannot trust my own typing or other people's sample code or maths. To ensure the results are as intended I have validated the code above using versions of the following method, one for each axis. I am not sure if this is 'Unit Testing' but it is my interpretation.
/// Check that the result of the quaternion elements is facing where expected.
There is significantly more code to check the results so the above just shows validating the forward vector but it should be obvious where to change that to do the Up and Right axes vectors.
I have many bits of maths and other methods that I need to ensure produce the results I expect, so I have similar debug code that I can run as stand alone methods to test the result of sections of code.
I hope the above is useful to some of you.
I have a little bit more to do to get the AI to use the newly added history of states and then I can get on with creating the server side code.