I set it up in my game so that an ogre can shoot arrows toward the player using a long bow in its possession. So far, I did not give a limit to the number of arrows that the ogre has on hand, and it just shoots an unlimited amount of arrows toward the player (I will change this for realism in the future). I also set it up so that the .mdl models serving as the arrows that get shot by the ogre, ricochet against hard walls (in the event of missing the player), and fall on the ground (staying visible), so that the player can choose to pick up the arrows and add to its inventory, if need be.

However, I notice that after a little while of the ogre shooting unlimited arrows toward the player, and missing (missed arrows falling on ground), the game starts to get really slow and choppy. I assume this happens because the more .mdl model arrows that get shot and fall on the ground while staying visible for the player to pick up if she/he so chooses, the more memory that takes up. Each .mdl arrow model is 372 KB.

Here is my code making this happen:

Code:
action shootArrowEnemy()
{
   ...

   while(1)
   {
      ...

      if (you == player) // arrow hit player?
      {	
         snd_play ( sndExplo, 100, 0 );
				
	 ent_remove(me);
	 return;
      }
      else // arrow missed player
      {
         vec_to_angle(my.pan,bounce); // and bounce off any 
                                      //    obstacles
      }

      ...

      wait(1);
   }
}

action ogre_archer()
{
   ...

   vec_set(temp, hero.x);
   vec_sub(temp,my.x);
   vec_to_angle(my.pan, temp); // turn the enemy towards the 
                               //    player

   my.ANIMATION += 3*time_step;		
   ent_animate(me,"bowShoot",my.ANIMATION,ANM_CYCLE);

   if (my.ANIMATION > 100) 
   { // shoot the bow			   
      ent_create("arrow.mdl",vec_for_vertex(v, me, 
         164),shootArrowEnemy);
      snd_play ( sndShootArrow, 100, 0 );
					
      my.ANIMATION -= 100;    // continue the cycle from the 
                              //    beginning
   }

   ...
}



Is there a way to make the fallen (missed) and visible arrows (that the player can pick up) to have a smaller memory footprint, so that the game does not slow to a crawl and crash, after so many arrows are fired and fallen to the ground?

Last edited by Ruben; 08/10/16 08:59.