- Home /
Question by
xcraftminebob · May 14, 2019 at 11:54 PM ·
physicsspawningspawning problemsspawning-enemies
Physics.CheckSphere Not Working
public void spawnObstacles(Transform t){
for(int i = 0; i < obstacleDensity; i++){
Obstacle obs = obstacles[Random.Range(0, obstacles.Length)];
//generate a random position (local scale)
Vector3 randomLocalPos = new Vector3(Random.Range(-5, 5), obs.obstacleModel.transform.position.y, Random.Range(-15, 15));
//if there are no colliders at the local position converted to world position in layer 9
if(!Physics.CheckSphere(t.TransformPoint(randomLocalPos), 4, 1 << 9)){
GameObject newObstacle = Instantiate(obs.obstacleModel, t);
newObstacle.layer = 9; // confirm that the new object's layer is 9
newObstacle.transform.localPosition = randomLocalPos;
}
}
}
This does not work. I still find objects (all set to layer 9) on top of eachother. My goal is to keep the randomly spawned objects from spawning on top of eachother. Is there anything here that would make it not work? Any help is greatly appreciated. I am pretty much desperate right now :)
Comment
Your answer
Follow this Question
Related Questions
Spawning help 1 Answer
Respawn script not working! 0 Answers
How to spawn enemies at different locations and avoid overlapping each other 2 Answers
How to spawn all humans at once and activate then with time? 1 Answer
Question about Unet and spawning 0 Answers