SetDirection Has side effects
Posted by Andrew / 19th January 2010 in Production Diaries
Back in the first week of production, we were using Euler angles to create the world matrix for an entity. Now we have converted to using directional vectors, and believe me, it wasn’t pretty. Our problem – SetDirection only modifed one axis of the matrix. As an entity rotated, the forward direction would become aligned with the right direction, and the resulting world matrix was no longer a rotation, but a scale as well.
End result – The sky dome slowly rotated, shrinking in the x direction as it went, and eventually collapsed (Help, the sky is falling!!!!). We also had some amusing results when the player collided with the terrain and changed direction as a result – you could shrink or grow the player depending on the direction of the collision.
The Fix – Make sure all 3 axis are rotated the same, and normalise them to stop scaling.