BlendAnim
Mixes a second animation over the current one.
Parameters
- entity
- entity handle
- sequence
- the animation sequence to mix in, or -1 to stop mixing
- weight#
- how much of it to mix in: 0 (none) to 1 (all of it, replacing the animation playing)
- mode (optional)
- how the mixed sequence plays: 1 loop (default), 2 ping-pong, 3 one-shot, 4 in step with the animation playing
- speed# (optional)
- speed of the mixed sequence. Defaults to 1. Not used with mode 4.
Description
Mixes a second animation sequence over the one started with Animate.
Use it to change smoothly between animations by amount rather than over time: mix sprint over walk by how fast a character goes, a wave over idle, an aim over a run. Calling BlendAnim again with the same sequence only changes the weight, mode and speed, so it can be called every frame - for example BlendAnim hero,sprint,speed,4.
Mode 4 keeps the mixed sequence at the same point of its cycle as the animation playing, which keeps the feet of a walk and a run together even when the two are different lengths.
BlendAnim works on .glb, .gltf, .fbx, .x and .3ds animations. To blend from one animation to the next over a number of frames instead, use the transition parameter of Animate.
Example
; BlendAnim example (an ArcBasic extension); Up/Down changes her speed: walk and sprint are mixed to matchGraphics3D 640,480SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,.8,-2.5CameraClsColor camera,150,200,240light=CreateLight()RotateEntity light,45,30,0; a Kenney character (www.kenney.nl, CC0)hero=LoadAnimMesh("../../../media/kenney/mini-characters/character-female-a.glb")TurnEntity hero,0,150,0walk=FindAnimSeq(hero,"walk")sprint=FindAnimSeq(hero,"sprint")Animate hero,1,.5,walkspeed#=.5While Not KeyDown(1) If KeyDown(200) And speed<1 Then speed=speed+.01 If KeyDown(208) And speed>0 Then speed=speed-.01 ; sprint mixed over walk by speed, in step with it (mode 4) BlendAnim hero,sprint,speed,4 UpdateWorld RenderWorld Text 0,0,"Speed: "+Int(speed*100)+"% (Up/Down)" FlipWendEnd
