Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Grady · Jan 02, 2012 at 01:59 AM · spawnspawningfogenemies

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
3

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Grady · Jan 02, 2012 at 03:07 AM 0
Share

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????

avatar image
2

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 } }

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Grady · Jan 02, 2012 at 12:04 PM 0
Share

Thanks for your reply @aldonaletto ! I'm not at unity right now, but I will test it after!!!

avatar image Grady · Jan 14, 2012 at 12:33 AM 0
Share

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?

avatar image aldonaletto · Jan 14, 2012 at 12:50 AM 0
Share

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)

avatar image Grady · Jan 18, 2012 at 10:26 PM 0
Share

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 :/

avatar image aldonaletto · Jan 19, 2012 at 12:02 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges