- Home /
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.... :/
Is there a better way of spawning enemies, then making them instantiate out of predefined game objects placed around the map??????
Thanks!
-Grady
Answer by Owen-Reynolds · Jan 02, 2012 at 02:34 AM
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.
ok thanks, ill have a bit of a look around!!!!!!!!
Would there be any way to sort of make them spawn at random locations, or would be keeping the game objects like i've got at the moment be the thing to do????
Answer by aldonaletto · Jan 02, 2012 at 10:09 AM
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 } }
Thanks for your reply @aldonaletto ! I'm not at unity right now, but I will test it after!!!
thanks, sorry for the late reply!!!!! I tested it, and dragged my spawn points in, but it is spawning all these zombies in one random location.......
Is that supposed to be the case?
No way! $$anonymous$$aybe a stupid error I made is the responsible: I wrote lenght ins$$anonymous$$d of length in the Random.Range arguments (damned word!). I fixed the answer - try it again (the enemies should appear at a point randomly selected from spawnPoints)
the script still seems to have some errors..... I can't get the zombies to actually spawn at the exact point of the spawn point, and sometimes they are higher off the ground...... and when i added that script to one of the spawn points, the actual spawn point game object started moving at the same speed as the enemies :/
This script should be attached to an empty object - you may call it Enemies, since it will be parent of all enemies - and this object must not move, or all enemies will move with it!
The function RandomPos adds an uncertainty margin in the line below:
pos += rndRadius * Random.insideUnitSphere; // <- add some random margin...
You can remove this line if you want the enemies to spawn only at the spawn points.
The height at which the enemies are spawned is found by raycasting downwards from a high position, plus the parameter height passed to the function RandomPos (it's 2 in the example above).
I tested this script, and it works fine - but the simple Update function was intended just as an orientation on how to use RandomPos and the enemy population control. It doesn't provide any interval between enemy spawning, what may cause some enemies to spawn over the others initially.
Your answer
Follow this Question
Related Questions
Enemies spawn on top of each other(C#)(Unity) 1 Answer
Spawn Object based on previous Scene Selection? 0 Answers
how can I destroying a spawn object ? 1 Answer
Spawn enemy while player is alive.... 2 Answers
Spawn random Obstacles along the x-axis 0 Answers