03-02-2017, 12:43 PM
(02-23-2017, 06:20 PM)Jake Wrote: Sorry, my fault. I forgot that Animate doesn't raise events. The problem is that the Animate feature doesn't move along the spline, but instead warps based on a curve.
So back to your original problem, I'd like to focus on my original idea, a custom controller that alters movement speed (no Animate, just regular movement) by distance from/to adjacent CPs.
Something like this inside your custom controller:
Sure it needs a bit more polishing (ensure you set speed back to original value if outside influence range, handle segments shorter than influence range etc...), but this may work well.Code:public AnimationCurve SpeedTween; // a curve describing either change of speed or absolute speed, depending on the way you want to work
public float TweenStartDistance=1; // distance in world units TOWARDS a CP to begin tweening =>Evaluate(0) of the above curve
public float TweenEndDistance=2; // distance after a CP to end tweening => Evaluate(1) of above curve
protected override void Advance(ref float tf, ref int direction, MoveModeEnum mode, float absSpeed, CurvyClamping clamping)
{
// Either advance before speed change or afterwards. Here we do it before
base.Advance (ref tf, ref direction, mode, absSpeed, clamping);
// Steps:
// Convert TF to current segment and distance within it
// Check, if it's in the "influence range" around the CP
// If yes, alter speed
float localF;
var seg = Spline.TFToSegment(tf,out localF);
float localDist=seg.LocalFToDistance(localF);
if (localDist<TweenEndDistance || localDist)
{ // acceleration phase
// map localDist to 0..1 inside the curve
Speed+=SpeedTween(mappedValue);
} else if (seg.Length-localDist<TweenStartDistance)
{ // brake phase
// map localDist to 0..1 inside the curve
Speed+=SpeedTween(mappedValue);
}
}
Perhaps use two animationcurves (or even better, checkout DTEase class of DevTools, it contains the regular, well-known easing methods).
Cheers
Jake
Using that code as a base I managed to accomplish the effect desired.
Thank you so much for all your help
Andrés