In my script, enemies spawn in a circle around the player. The problem is, they tend to spawn into walls. What I tried to do was to detect if they collide with a wall at spawn, and if they do, move them to a spawn point I set up. My Script that detects the collision looks like this:
void OnCollisionEnter(Collider collider)
{
if (collider.gameObject.tag == "wall" && alreadySpawned == false) {
alreadySpawned = true;
enemy.MovePosition(spawnPoints[Random.Range(0, spawnPoints.Length)].transform.position);
Debug.Log("I spawned");
}
}
I have no idea why it doesn’t work. Maybe because I use mesh colliders? (I create simple shapes in blender fot the collider, import it to unity and use a mesh collider on it)
Thanks