Using fog/mist to disguise enemy spawning

Hey guys,

I am trying to use fog to disguise when my enemies spawn in the middle of nowhere, except I am having a couple of problems…

The first one is, my game’s terrain, is just a slighly hilly terrain with a night skybox (pretty much flat) with trees everywhere… (a sort of spooky type thing!!!)

Now that I have added fog, I wanted it to be hovering just under the treeline, just at about eye level, to disguise the actual enemy spawning… But the fog is hovering everywhere, making the trees outline go white, and it looks weird… Is there any way to change the height of the fog???

And the second thing is, in attempt of using the fog to disguise when the enemy spawns, when the player gets to the actual game object that I am have placed to make the enemy spawn from, because you can get right up to it, and there is no fog, you can see the enemies spawning right in front of you… :confused:

Is there a better way of spawning enemies, then making them instantiate out of predefined game objects placed around the map???



Fog is built into the graphics card (which is why it’s so fast) strictly as a function of distance.

You could make a big “ninja cloud” particle effect to hide spawns. Or make a big tent and spawn enemies halfway out of the flap, as if they are leaving. Or have them rise out of the ground, with a “dirt rumble” effect, or start them transparent and fade them in… .

Take a look at games that spawn things where you can see. They often use pretty cheesy tricks, which look fine.

You can manually place several spawn points and drag them to an array of spawn points (don’t mind about the precise Y - it will be fixed later); select one of them using Random.Range(0, spawnPoints.lenght), and add a small uncertainty margin adding Random.insideUnitSphere * rndRadius to the position. Finally, set the position Y to a safe height: set Y to a high value, raycast to the down direction to find the ground coordinate. To keep the enemy population under control, you can add the spawning script to an empty object, child every spawned enemy to it and use transform.childCount to know how many enemies are currently around - something like this basic code, which you can improve with particle special effects:

var enemyPrefab: Transform;
var maxEnemies = 10;
var spawnPoints: Transform[]; // drag the spawn empty objects here
var rndRadius: float = 3; // random circle radius around the spawn point

function RandomPos(height: float): Vector3 {
  // randomly select a spawn point:
  var pos = spawnPoints[Random.Range(0, spawnPoints.length)].position;
  pos += rndRadius * Random.insideUnitSphere; // <- add some random margin...
  pos.y = 2000; // <- set the position at a big height...
  var hit: RaycastHit; 
  // and find ground with Raycast:
  Physics.Raycast(pos, -Vector3.up, hit);
  pos.y = hit.point.y + height; // get the ground Y plus the desired offset
  return pos;

function Update(){
  if (transform.childCount < maxEnemies){ // population control
    var rndRot = Quaternion.Euler(0, 360 * Random.value, 0);
    var rndPos = RandomPos(2);
    var enemy = Instantiate(enemyPrefab, rndPos, rndRot);
    enemy.parent = transform; // child the enemy to this object