Pima-GAM150 / Chandler-and-Morgan-Duo

0 stars 0 forks source link

Enemy Spawn issue #3

Open ChandlerHostetler opened 7 years ago

ChandlerHostetler commented 7 years ago

Enemies are spawning but I'm not sure how to spawn them in specific locatons

mjackson34 commented 7 years ago

In spawnEnemy.cs line 17: Instantiate(enemy, new Vector2(Random.Range(100, -100), Random.Range(100, -100)), Quaternion.identity);

The Random.Range parameters are backwards, they should be Random.Range(-100, 100).

mjackson34 commented 7 years ago

Spawn in a circle around a point:

//get player's location
Transform location = player.transform;
//generate a random angle
float ang = Random.value * 360;
//set the radius from the player that the enemy will spawn
float radius = 10f;
//create the location that the enemy will spawn
Vector2 pos;
pos.x = location.position.x + radius * Mathf.Sin(ang * Mathf.Deg2Rad);
pos.y = location.position.y + radius * Mathf.Cos(ang * Mathf.Deg2Rad);
//use pos as the location for instantiating the enemy