SPLINES and enemies paths
- August 18, 2014
- 3 Comments
The shmup Creator offers the choice to use a precise and predictable curve animation, using splines to move the enemies.
Splines are great :the user can create some points, move them, and play with curves very quickly and visually. There are a lot of tutorials and articles on the subject, which is good, as the maths behind them are way beyond my grasp!
But I’ll talk about some of the issues I encountered when I implemented them, and the solutions I found.
. Which type of splines ?
There are a gazillions of splines algorithms out there. The most all around type of spline, in my opinion, is the Catmull-Rom spline. Unlike the bezier splines, the Catmull-Rom curve is really following the control points, and I found it easier to predict his shape this way. It’s also easy to modify the spline tension of the entire curve (which, by default, is 0.5), to create straight lines, or more or less curvy paths.
. Individual point tension
One thing I like a lot in the way Adobe After effects implemented their splines, is the possibility to modify the tension of an individual point. I looked everywhere for a proper algorithm which could do this, and it was not easy to find one. And one day, I read about a way to compute the canonical or cardinal spline which was perfect for what we wanted to achieve :http://www.charlespetzold.com/blog/2009/01/canonical-splines-in-wpf-and-silverlight.html
Each point can have a position and a tension, and therefore it’s really easy to control the look of the curve, and the path of the enemy. For ease of use, I force a tension of 0 (straight) for the first and last point of the curve, to avoid unwanted small bumps. There is also the possibility to close the spline and to loop the path (and in this case, I’m not forcing the 0 tension at the extremities) .
. Constant speed on a spline
When we tried to move an enemy on this spline, we quickly discovered that it was not moving at a constant speed. The enemy was slowing down and speeding up depending of the curve shape. And we couldn’t at all control the speed (like having an object moving at 5m second) because this speed was dependent of the curve.
The solution to this problem is called arc-length re-parameterization. Behind this barbaric name is a way to store distances in a look-up table to have informations about the real distance of the curve when we are doing the interpolation.
I’m not going to explain the technique in my post, not because I’m lazy, but because Motorherp wrote a great article on the subject in the shmup-dev forum :http://cokane.com/shmupdevarchive/index.php?action=printpage;topic=1638.0
It’s a really informative and well written piece, so I encourage everyone interested in the subject to read it.
So, at the end, we have complete control of the spline curve, the speed of the enemy, and on top of that, we added ways to stop the enemy for some time when he arrives at a certain point, to rotate it, to orient it in different ways…
Everything is easy and fun to use, and is really graphic, which is the main idea behind our tool.
Thanks for reading!
And, as always, pay us a visit on twitter!