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
  Getting Distance from a World Point zorksox 3 5 04-16-2024, 07:30 PM
Last Post: _Aka_
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 3 11 04-02-2024, 02:24 PM
Last Post: _Aka_
Question Volume Spots inter group distance Sacryn 1 3 02-27-2024, 04:08 PM
Last Post: _Aka_
  Distance travelled across multiple splines jh092 1 7 02-23-2024, 09:44 AM
Last Post: _Aka_

Forum Jump: