- Home /
Spawning entities around player in a distance?
I am making a game that has a never ending terrain and constantly updating i want zombies to spawn from a distance where player can and cant see please help me.....
I want zombies to be spawned like a 200 block radius and can stay on the map.
Answer by gardian06 · Sep 18, 2013 at 10:18 PM
spawn the "thing" using this, but to get the "distance where player can and cant see" part then you might need to do some work.
assuming a flat area that the player is standing on then you just constrain your y, and get random values for your x, and z values of the position. just use
Vector3 position = Vector3.zero;
position.x = Random.Range(player.position.x-xVary,player.position.x+xVary) // player is the transform of the player, and xVary is a public float (for balancing)
but before you use that vector in the instantiate then you might want to do a Physics.RayCast() to see if that would be in line of the player (if there is a lot of things around the player like dense forest this might get tricky), but for the not off the edge of the world thing just do a RayCast(position, Vector3.Down)
mind you that this was assuming a large flat area, and if you have a lot of hills, or uneven terrain then this will require a fare bit of modifications
ill try this but its not flat its like $$anonymous$$e craft generation or voxel generation random
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
'else' not working.... please help:( 4 Answers
Repeat enemy spawn wave script ? 0 Answers
GUI Mini-Game 0 Answers