I’m trying to use http://www.unifycommunity.com/wiki/index.php?title=Spline_Controller to create a path in which the player character should be able to move, rather than on a straight line in a single axis. I am having some issues at doing this, and I almost posted a question here to ask for help, but I ended up solving at least the first big one by myself.
So I decided I will catalog here this quest. If anyone wants to bump in, be welcome. Following there will be the first issue, and as of now I still don’t have it completely solved.
Mostly the SplineController seems to work. Even the spline among the spheres is traced just fine (although I rather have straight lines, but this is another subject). But as soon as I add the script to the 2D platform game demo, by following the instructions, I get this warning:
Line 24 is this:
var interp = new SplineInterpolator();
SplineInterpolator is the other JS provided.
I couldn’t see what was wrong with this because I don’t know how this should be done. But then I realized AddComponent was used few lines below, at 44, as this:
mSplineInterp = gameObject.AddComponent(SplineInterpolator);
So I just copied it and the warning was gone!
The following didn’t really help me for this issue:
But reading the Scripting Tutorial was important to realize it should be a simple issue, rather than maybe having to do everything in a different new way.
Turns out that my “fix” actually generates a much worst bug - Unity leaks out memory by keeping adding infinite SplineInterpolator components to the object where SplineController is a component. I think it starts after pressing play and stop the first time. Anyway, I reverted to the original, and I still don’t know how to take out the warning, but I’ll just ignore it for now.
We gave up on the spline, came up with another idea, but it also turned out to be bad, so we went back to spline, and today we’ve finally have fixed the warning.
Just needed to replace the given line to:
var gSplineInterp : SplineInterpolator = gameObject.GetComponent(SplineInterpolator);
And add the SplineInterpolator component to the same object from SplineController.
That’s all for now.
Next step will be making our custom PlatformController following the spline rather than standing in just one axis.
I’ll try to attach here two images to illustrate what we want to do.
We deviated from this goal because it was just not working, now we are taking on it again and hopefully for good!
The first image I’v attached shows the top view with the spline. It has just 4 spots, and that is the path the character, and every other rigidbody, should follow as it were just a 2D plane.
The second one shows the character on the track, and how dense the spline gets right on the curve. This behavior is expected from a spline, but not good for physics, and it must be avoided.
If I’m to set the character just using the spline time, it will get much slower right there.
Next step I’ll be trying is something using Point nearest-neighbour search class. The idea is using the SplineController to build few invisible objects in the scene, and then make the objects snap to them. Or at least to their X Z positions.
It’s either that or, what would be better, figuring a math function that can modify the X Z directions according to their position alone. I’m pretty sure it’s possible, just couldn’t yet figure out how.