Hermite Spline Controller Question

Hi All,

I’m trying to get back onto the Unity saddle sort of speak and was confornted with a seemingly ‘simple’ request but i don’t possess the scripting knowledge to figure how to make it work.

I have a hermite spline controller in a scene that works great, thanks to this tutorial off Unify Wiki:

http://wiki.unity3d.com/index.php/Hermite_Spline_Controller

What I am asking is if it’s possible to add user control to the “hermite spline controller” as defined in this OTHER tutorial? because as is–the hermite is a looping action with no control except for where you place your nodes. I’d like to take it to another level. Here’s the first and older tutorial:

http://wiki.unity3d.com/index.php?title=Spline_Controller

I would like to have all the features (stop, go, pause, adding nodes, removing nodes, etc) included into the Hermite Spline Controller script. Basically infuse both tutorial scripts into one?

I’ve had a go at it, and i just get compiler errors and thought i’d give the community a try!

Thanks!

I basically would like to know if it is possible to toggle a “pause” along the spline path for my camera. Allowing the viewer to stop at a certain point along the fly-through to observe the environment?

Would it just work if you set mState to “Stopped” ?

I am a C# noob…(Scripting language in general…) I’m afraid I don’t know the proper syntax to insert such a statement. Or is mState JavaScript? I’d like to just toggle a pause and unpause of the camera’s trajectory using the spacebar.

the scripts are written in JS.

If you look at the SplineInterpolator.js file and scroll down to “Update()” you will see where the first thing it asks for is. “Do I have a reason to quit this?” If yes, then it “stops”

You just have to set:

mState = “Stopped”;

You can do this on a with something like this:

	if(Input.GetKeyDown(KeyCode.X){
		if(mState == "Stopped"){
			mState = "";
		} else {
			mState = "Stopped";
		}
		//mState  = mState == "Stopped" ? "" : "Stopped";
	}

And yes, that goes into the Update, before everything. press X and it stops, press X again and it continues.

I’ve been trying to figure out the compiler error I’m getting when trying to use the above suggestion. I’m suspecting it’s a simple syntax error with the curly brackets as i get an EOF error–specifically the curly brackets at the beginning (after Update()) and at the very end. It looks like they should work? since they close each other out? but maybe i’m not seeing something…?

function Update ()
{
   if(Input.GetKeyDown(KeyCode.X){

        if(mState == "Stopped"){

            mState = "";

        } else {

            mState = "Stopped";

        }

        //mState  = mState == "Stopped" ? "" : "Stopped";

    }

	if (mState == "Reset" || mState == "Stopped" || mNodes.length < 4)
		return;
 
	mCurrentTime += Time.deltaTime;
 
	// We advance to next point in the path
	if (mCurrentTime >= mNodes[mCurrentIdx+1].Time)
	{
		if (mCurrentIdx < mNodes.length-3)
		{
			mCurrentIdx++;
		}
		else
		{		
			if (mState != "Loop")
			{
				mState = "Stopped";
 
				// We stop right in the end point
				transform.position = mNodes[mNodes.length-2].Point;
 
				if (mRotations)
					transform.rotation = mNodes[mNodes.length-2].Rot;
 
				// We call back to inform that we are ended
				if (mOnEndCallback != null)
					mOnEndCallback();
			}
			else
			{
				mCurrentIdx = 1;
				mCurrentTime = 0.0;
			}
		}
	}
 
 	if (mState != "Stopped")
 	{
 		// Calculates the t param between 0 and 1
		var param : float = (mCurrentTime - mNodes[mCurrentIdx].Time) / (mNodes[mCurrentIdx+1].Time - mNodes[mCurrentIdx].Time);                                                                                                                                                                                                                                                                                                                                                
 
		// Smooth the param
		param = MathUtils.Ease(param, mNodes[mCurrentIdx].EaseIO.x, mNodes[mCurrentIdx].EaseIO.y);
 
		transform.position = GetHermiteInternal(mCurrentIdx, param);
 
		if (mRotations)
		{
			transform.rotation = GetSquad(mCurrentIdx, param);
		}
 	}
}

Hey y’all! Ok, I found the little error in the syntax. I was missing a regular bracket after the KeyCode at the top. It works now! and It’s great! I wonder what other functionality could be added? like a free-look while it is paused? might be too complex for it to be plausible, no? a whole other beast! just spitting out thoughts. I’d like to hear your thoughts, but overall thanks for the helping hand guys!

should be easy, just use the standard mouseLook or MouseOrbit with a distance of zero and disable/enable it when you need to.

oh yeah? i’ll give that a shot.

I have one more question after running through functionality, it seems that if i pause and unpause my camera trajectory at least once during its fly-through along the spline, the camera will stop at one cycle (at the end of the spline) and will no longer loop to repeat the path, as it did before. Is there a conflict where the pause function disables the ability for the camera to loop its trajectory?

Upon review and experimentation, seems like the blank mState quotes needed a “Loop” defined in order to keep the camera looping forever while still keeping stop and go function. Hooray!

and… that is how easy it is to mod programs. lol