Let's have some fun with math, especially linear algebra!
- Is this your idea of fun, Erik?
- Yes, when you see what you've learned is actually working in real life, then that's fun. Not fun as in drinking whiskey, but you get the idea...
When I studied linear algebra in school I had no idea when I would need to know if two vectors are pointing in the same direction or why you would ever need to use the cross product. But a few years later, I've found some practical problems to solve where I actually needed to know if two vectors are pointing in the same direction. I've collected these problems and their mathematical solutions in a new tutorial series: Use Linear Algebra to solve problems in Unity with C#.
The problems I've solved so far are:
- How to figure out if an enemy is in front or behind you?
- If you are following a series of waypoints how do you know if you have passed a waypoint?
- If you are steering towards a waypoint, how do you determine if you should steer left or right?
- How can you find the coordinate where a ray intersects with a plane?
- How can you tell if two line segments in 2D space intersect with each other?
The idea is to minimize the text and instead have finished code with comments that you can just copy and paste. Some of these problems you have solve in a rush. When I competed in the Ludum Dare competition, where the idea is to make a game in 48 hours, I needed to know if two line segments are intersecting with each other. But I couldn't solve the problem fast enough so I had to come up with another idea, which took some extra time and thus made the final game worse.