01-25-2018, 02:15 PM
(01-25-2018, 10:14 AM)akira_sh512 Wrote: This tool is very useful for me.
Thank you.
You are welcome
(01-25-2018, 10:14 AM)akira_sh512 Wrote: 1, Should I write some code in UserAfterUpdate() to control a path speed ?
If your enemies will simply follow the splines, then an approach similar to the one in the "01_MetaData" example scene should be enough.
Here is some code:
First, the SpeedMetaData class. Very similar to HeightMetadata from the example:
Code:
public class SpeedMetaData : CurvyMetadataBase, ICurvyInterpolatableMetadata<float>
{
[SerializeField]
float m_Speed;
public object Value
{
get { return m_Speed; }
}
public object InterpolateObject(ICurvyMetadata b, float f)
{
var mdb = b as SpeedMetaData;
return (mdb != null) ? Mathf.Lerp((float)Value, (float)mdb.Value, f) : Value;
}
public float Interpolate(ICurvyMetadata b, float f)
{
return (float)InterpolateObject(b, f);
}
}
then, the spline controller that uses the SpeedMetaData. Also, similar to the MetaDataController class from the example
Code:
public class TestSplineController : SplineController
{
/// <summary>
/// This is called just after the SplineController has been initialized
/// </summary>
override protected void UserAfterInit()
{
SetSpeed();
}
/// <summary>
/// This is called just after the SplineController updates
/// </summary>
override protected void UserAfterUpdate()
{
SetSpeed();
}
private void SetSpeed()
{
// Get the interpolated Metadata value for the current position (for SplineController, RelativePosition means TF)
// If values can't be interpolated (no next value), current value (if present) or default type value (for float that's 0) is returned
Speed = Spline.InterpolateMetadata<SpeedMetaData, float>(RelativePosition);
Debug.Log(Speed);
}
}
With those two classes, you will get variable speed for your SplineController.
Even if you don't use a spline controller, you can still use the spline's speed meta data. For example, the following code allows any object to retrieve the speed from the nearest spline point.
Code:
float currentTf = Spline.GetNearestPointTF(transform.position);
float speed = Spline.InterpolateMetadata<SpeedMetaData, float>(currentTf);
//SetSpeed(speed);
So this way, you can have the enemies move freely (outside of the spline) but still modify their speed based on the data in a spline. This can be used as a level design tool for example.
(01-25-2018, 10:14 AM)akira_sh512 Wrote: 2, Can I control a path speed with Meta CG Options?
MetaCGOptions, like HeightMetaData and SpeedMetaData all inherit from CurvyMetaDataBase. I don't see any gain to set the speed in MetaCGOptions instead of using your own metadata class.
(01-25-2018, 10:14 AM)akira_sh512 Wrote: 3, Are there any good way to set a speed to a path in Unity Editor. Because our artists have to set a speed in Unity Editor. (They don't want to edit any code.)
Like the Height in the example scene, the speed will be settable via editor. The artists can add a SpeedMetaData to any control point, and set it's value in the editor.
Let me know if you need further explanations.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.