Make an entity that flies through the air with c_move and the USE_POLYGON flag. When it hits another entity, you can make it stick by calculating the distance vector between the grenade and the hit entity and then set the grenade to the position of the hit entity + the calculated distance vector.

Here's an untested example action explaining what I mean:

Code:
#define reldist_x skill1
#define reldist_y skill2
#define reldist_z skill3
#define absdist_x skill4
#define absdist_y skill5
#define absdist_z skill6
#define entity_handle skill7

action grenade()
{
  my.reldist_x = 16; // forward velocity
  my.reldist_y = 0;
  my.reldist_z = 0;
  my.absdist_x = 0;
  my.absdist_y = 0;
  my.absdist_z = 16; // the grenade flies upwards at first.

  while( my ) // while I exist
  {
    if( !is(my,FLAG1) ) // "flying through the air" mode
    {
      my.absdist_z -= time_step; // the grenade flies downward over time.
      c_move( my, my.reldist_x, my.absdist_x, USE_POLYGON );
      if( trace_hit && you ) // hit an entity
      {
        // remember the entity I hit with a handle
        my.entity_handle = handle( you );

        // go to "sticky" mode
        set( my, FLAG1 );
      }
    }
    else // "sticky" mode
    {
      your = ptr_for_handle( my.entity_handle );
      if( your ) // only do this if the entity still exists, of course (otherwise we get a pointer error)
      {
        // In sticky mode, I repurpose my.absdist to be the position of the grenade + the distance between the grenade and the hit entity.
        vec_diff( my.absdist_x, my.x, your.x );
        vec_add( my.absdist_x, my.x );
        vec_set( my.x, my.absdist_x );
      }
    }

    wait(1);
  }
}



When this action is assigned to an entity, it will fly through the air with an initial upward velocity and begin to descend. When it hits another entity, it enters "sticky mode" and begins to stick to the entity!

Hope that helped. wink

Last edited by Redeemer; 03/08/11 15:40.

Eats commas for breakfast.

Play Barony: Cursed Edition!