Game Development Reference
In-Depth Information
Linear blending
To implement linear blending, we create two types of linear blend functions. One function
takes an animation and eases the animation's weight to zero over a duration of time, and an-
other function takes an animation and eases the animation's weight to one over a duration
of time. Both of these functions are meant to be called during the update loop till the anim-
ation is completely blended in or blended out.
Once these two functions are implemented, we can combine both of them into a Lin-
earBlendTo function that will blend one animation out when another animation is blen-
ded in:
Sandbox.lua :
local function clamp(min, max, value)
if (value < min) then
return min;
elseif (value > max) then
return max;
end
return value;
end
function LinearBlendIn(
animation, blendTime, startTime, currentTime)
blendTime = clamp(0.01, blendTime, blendTime);
local percent =
clamp(0, 1, (currentTime - startTime) / blendTime);
Animation.SetWeight(animation, percent);
end
function LinearBlendOut(
animation, blendTime, startTime, currentTime)
blendTime = clamp(0.01, blendTime, blendTime);
Search WWH ::




Custom Search