Using ent_create, this script will spawn a new
entity from a model not currently in the 3D enviroment
and place it behind the target entity. The target can
be moving/rotating.
Code:
//set the model you will be using for the spawned entity
string spawnEntity = "yourModel.mdl";
//
//
//set the distance from the target entity you want to spawn to
var spawnDistance = 30;
//
//
function spawnTheThing()
{
//get outta here if there aint no target entity in the game
if(targetEntity == NULL)
{
return;
}
//set temp to the vector of the target entity
vec_set(temp.x, targetEntity);
//this is the same idea used in a 3rd Person Camera
//it will place the spawned entity behind the target entity
//taking the rotation of the target entity into account
temp.x = targetEntity.x - spawnDistance * cos(targetEntity.pan);
temp.y = targetEntity.y - spawnDistance * sin(targetEntity.pan);
//set spawnEntityAction to NULL if you do not want to asign it a function
ent_create(spawnEntity,temp.x,spawnEntityAction);
}
Just call the function, and you'll get a new entity every time!