Creating a Static Spline Editor in Unity

Before the production of Edge of Home and Space Dreams ramped up, I was tasked with creating some tools that could be used during the development process. I knew that we were going to be developing for the Google Cardboard and there were several designs on the table. One of the biggest limitations we had was the lack of meaningful player input. Basically, all the player can do is look around and press a button. To make things worse, the button didn’t work (or didn’t exist) on many of the available Cardboard headsets on the market.

The lack of input the player had meant that we had to come up with a method of moving the player. Many of the designs featured player movement, whether it was between different rooms or rotating around an object. This led me to believe that creating an editor tool for player movement would be a good idea. After some research, I decided that a spline-based movement tool would be the most flexible option.

Movement

movement

The first thing I did was get an object to move from point A to point B. With spline-based movement, the user can define a series of points to move between. The script then creates a path between the points using one of the spline equations. I decided on the Catmull-Rom spline because it will always go through its control points (in contrast to a Bezier curve), making it easier to visualize for the user.

Next, I had to actually move the object! I was torn between two different methods: movement relative to the curve and movement relative to velocity. Both had their advantages: movement relative to the curve made timing cutscenes more intuitive, while movement relative to velocity helped avoid unexpected changes in speed. I eventually decided to put both in alongside other features like looping and having an open or closed path.

Rotation

rotation

While the player can rotate their camera on their own, there are certain situations where we might want to direct the player’s location to a certain point. Additionally, this system could be used for objects other than the player camera. So rotation was a critical feature that needed to get in. The user can set the rotation of each point on the spline that they define, and the curve will interpolate between the rotations using the SQUAD (Spherical and Quadrangle) method. The rotations are visualized as lines coming out of the spline. The user can define whether the curve uses rotations or not in the editor.

Inspector

inspector

To make things easier for the user, a custom inspector was implemented. The curve is considered a “Path” and each point on the curve is considered a “Path Node”. The user places the transform of the object they want to be controlled by the spline into the “Move Transform” field. Then, they can create a path without have to create any objects themselves just by pressing “Add Path” and then adding as many nodes as they want. Additionally, an API was created that allows the user to start and stop objects on their curve from code as well as set the speed dynamically. The rest of the parameters must be set before the scene is played, since the splines are baked at the start of the game.

Conclusion

While there exist more fully-featured spline path editors on the Unity Asset Store, this simple tool found plenty of use during production. Along with a metrics and analytics API for heatmaps and data collection and a gaze-based input event system, the tools I made for the project ended up saving the development team time and allowed them to focus on creating great experiences.