ent_animate(ENTITY* entity, STRING* scene, var percent, var mode)

Animates a model, terrain or sprite entity by setting it to an interpolated position within a cyclic or non-cyclic animation scene.

ent_animatefrom(ENTITY* entity, ENTITY* source, STRING* scene, var percent, var mode)

Like ent_animate, but loads the bones animation from a separate entity. This way entities can share bones animation scenes. A7.82  LC 

Parameters:

entity Entity to be animated.
source Entity that contains the animation scene. For bones animation only; the skeleton of both entities must be identical.
scene Name of the bones or vertex animation scene without the trailing number, or NULL for resetting frame, nextframe, and the entities' skeleton to their default states. Resetting the skeleton is required before combining a bones animation.
percent Animation percentage within the scene, 0..100. At 0 the first frame is selected, at 100 the last frame (which is identical with the first for cyclic animation).
mode

to be combined from the following predefined values:

ANM_SKIP For not interpolating the frames.
ANM_CYCLE Cyclic animation scene, like walking or running. Otherwise it's a noncyclic scene like jumping or shooting.
ANM_ADD For combining a bones animation from several ent_animate calls. Adds the new bones angles to the current angles, rather than replacing the current angles by the new ones.

Returns:

> 0 number of the target frame for a vertex or sprite scene
< 0 target frame for a bones scene
0 no scene with the given name was found

Modifies:

entity.frame set to the current frame plus interpolation factor.
entity.next_frame set to the next target frame for interpolation, or reset to 0.

Speed:

Medium (vertex, sprite, or GPU bones animation)
Slow (CPU bones animation)

Remarks:

Edition:

 C   P  for bones frames. Vertex and sprite frames can be set with all editions.

Examples:

// run a walk animation
action vertex_anim()
{
   while(1) 
   {
      my.skill1 += 3*time_step;
      if (my.skill1 > 100) my.skill1 -= 100; 
      ent_animate(me,"walk",my.skill1,ANM_CYCLE);
      wait(1);
   }
}

// let a model run, and smoothly blend over to shooting when [Ctrl] is pressed
action bones_anim()
{
   while(1)
   {
      my.skill1 += 3*time_step; // torso animation
      my.skill2 += 3*time_step; // legs animation

      if (key_ctrl) // fire key pressed?
      {
         my.skill3 += 20*time_step; // blend factor for 1-frame shooting animation
         my.skill3 = min(my.skill3,100); // clip at 100 percent
      } else {
         my.skill3 -= 20*time_step;
         my.skill3 = max(my.skill3,0); // clip at 0 percent
      }

// reset skeletion and then compose the animation (order is important): 
      ent_animate(me,NULL,0,0); // reset all bones
// first, shake the arms during running
      ent_animate(me,"run_torso",my.skill1,ANM_CYCLE);
// then blend over to, or blend back from shooting (only affects the arms)
      if (my.skill3 > 0) { ent_blend("shoot",0,my.skill3); }
// finally animate the legs (only affects the legs)
      ent_animate(me,"run_legs",my.skill2,ANM_CYCLE+ANM_ADD);
     
      wait(1);
  }
}

See also:

ent_blend, pose ► latest version online