Posts: 8
Threads: 3
Joined: Feb 2016
Hi all,
I'm new user of curvy
And I have some beginner questions
1. How can I move object by 5 units on spline? (i need to make patrol agent that he moves by specific distance on spline)
2. How can I change splines smarter way than entering on trigger?
Thanks for any help
Posts: 690
Threads: 71
Joined: Jan 2015
Hi Szagi,
1.) Use a SplineController and set it's movement to "Absolute". Speed then means units/second. Enable Animate and set the animation properties if you want a one-shot or tweening behaviour.
2.) I don't understand that, can you please elaborate what you're after?
Posts: 8
Threads: 3
Joined: Feb 2016
Sorry for my bad explanation
1.) I didn't understood this well

Animate property can be use for this: my enemy moves for example 5 units, than stops, then change direction and moves 8 units?
2.)
http://imgur.com/HAjeUPX vertical wall is my trigger which changes splines from down spline to upper spline, but this is a bit jumpy and I have no idea how can I do it smoother
this is my code:
Code:
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player"){
PlayerSplineController wagon = other.GetComponent<PlayerController>().Wagon;
//TODO: changing splines is good thing to move to SplineManager
if (wagon != null) {
_enterDirection = Mathf.Sign (wagon.Speed);
Vector3 nearestPoint;
float nearestPointTF;
Transform newParent;
CurvySpline newSpline;
if (direction && _enterDirection > 0 || !direction && _enterDirection < 0 ) {
nearestPointTF = nextSpline.GetNearestPointTF(transform.position,out nearestPoint,7,8);
newSpline = nextSpline;
newParent = nextSpline.transform;
} else {
nearestPointTF = prevSpline.GetNearestPointTF(transform.position,out nearestPoint,6,7);
newSpline = prevSpline;
newParent = prevSpline.transform;
}
wagon.SwitchTo(newSpline, nearestPointTF, 0);
wagon.transform.parent = newParent;
}
}
}
Posts: 2
Threads: 1
Joined: Mar 2016
Hi all,
Can I use navmesh,A star path finding or other path finding algorithm on curvy2.02? may be curvy2.02 already have a best solution for the navigation algorithm.Thanks
Posts: 690
Threads: 71
Joined: Jan 2015
1.) Yeah, see the GUI example scene. The buttons and the label are using the Animate feature, i.e. they move a delta, then move back. But the same Animation feature can be used to move a certain distance and then stop, including slowdowns and other tweanings.
2.) Triggers are one way, another one would be to utilize controller events such as OnEndCPReached/OnCPReached. Then you get a callback each time the controller moves over a CP and you can switch splines there. Use connections to easily access the next/previous spline in question. For some examples, see CurvyDefaultEventHandler.cs.
Posts: 8
Threads: 3
Joined: Feb 2016
1) But from code it is possible?
Posts: 690
Threads: 71
Joined: Jan 2015
You can use the SplineController from code like any other GameObject. All inspector options and commands (stop/start/play/reset etc.) are available by code as well.
Posts: 8
Threads: 3
Joined: Feb 2016
I tried this Animate feature but with more complex AI or a couple move patterns it is a bit messy and hard to control or tweek. There is maybe different way to move something by specific distance from code?
Posts: 690
Threads: 71
Joined: Jan 2015
Yeah, make a custom controller and use Spline API to move the object the way you like, e.g. CurvySpline.MoveByDistanceFast().
Posts: 8
Threads: 3
Joined: Feb 2016
06-06-2016, 06:33 PM
(This post was last modified: 06-06-2016, 06:33 PM by Szagi.)
Thanks for all your help

You are the best!
I don't understand this method very well, but I created simple custom controller:
Code:
public class EnemyWagonController : SplineController
{
private float _tfValue;
private int _direction = 1;
void Awake()
{
Vector3 nearestPoint;
_tfValue = Spline.GetNearestPointTF (transform.localPosition, out nearestPoint);
transform.localPosition = nearestPoint;
}
public override void Refresh ()
{
Move ();
}
void Move()
{
Vector3 nearestPoint;
_tfValue = Spline.GetNearestPointTF (transform.localPosition, out nearestPoint);
transform.localPosition = Spline.MoveByLengthFast (ref _tfValue, ref _direction, 2f, CurvyClamping.PingPong);
}
}
And I assume MoveByLengthFast(ref float tf, ref int direction, float distance, CurvyClamping clamping) distance is speed, but how can I track my controller reached target distance?
Sorry for my stupid questions.