Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Animate movement with curve by distance, not time
#8
(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:

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);
  }
}
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.
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
Reply


Messages In This Thread
RE: Animate movement with curve by distance, not time - by yandrako - 03-02-2017, 12:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Smile Simple splines movement shills 3 3,220 02-26-2025, 09:40 AM
Last Post: _Aka_
  Morph game object along curve. mikechr2000 5 3,021 02-04-2025, 09:30 PM
Last Post: _Aka_
  Scaling a closed curve rickgplus 1 1,477 01-16-2025, 06:52 PM
Last Post: _Aka_
  Extrapolate past curve endpoint Madgvox 3 2,371 09-10-2024, 01:24 PM
Last Post: _Aka_

Forum Jump: