Interpolation/Target

From Second Life Wiki
< Interpolation
Revision as of 13:19, 4 September 2011 by Nexii Malthus (talk | contribs) (Created page with "{{LSL Header|Interpolation}} {{RightToc|clear:right;}} == Target == {|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; …")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Target

Float Target

Steps float 'Now' closer using float 'Vel' towards 'Target' while clamping between 'Min' and 'Max'. Useful for games, simulations and vehicles. For example keeping realtime track of linear and angular acceleration and velocity of a vehicle. <lsl> float fTarget(float Now, float Target, float Min, float Max, float Vel) {

   if(llFabs(Target-Now) < Vel) return Target;
   if(Now < Target) Now += Vel; else Now -= Vel;
   if(Now < Min) Now = Min; else if(Now > Max) Now = Max;
   return Now;

} </lsl>

Input Description
float Now 'Now' current value
float Target move 'Now' towards 'Target'
float Min Clamp output at minimum
float Max Clamp output at maximum
float Vel Move 'Now' towards 'Target' at 'Vel' (Velocity)
Output Description
return float fTarget Returns clamped output of a single step of 'Now' towards 'Target' using 'Vel'
Graph goes here, k.
Released to Public Domain. By Nexii Malthus