Quantcast
Channel: Answers for "Randomize the position of the player"
Viewing all articles
Browse latest Browse all 4

Answer by syclamoth

$
0
0
If you want to spawn in a random position, try using something like this: // having determined the spawnPoint, get a random point in a circle: var randomCircle : Vector2 = Random.insideUnitCircle; var spawnOffset : Vector3 = new Vector3(randomCircle.x, 0, randomCircle.y); var newTrans : Transform = Network.Instantiate(playerPrefab,spawnpoint.position + spawnOffset, spawnpoint.rotation, 0); Otherwise, if you want to have a large number of spawnPoints, you can either collect them with the use of a common tag, and use the code that you posted in your question (make sure that all the transforms that you are using as spawn points have the "Spawnpoint" tag), or you can manually define them by dragging them into an array in the inspector: // right at the top! public var spawnPoints : Transform[]; // then when you go to use it: var spawnPoint : Transform = spawnPoints[Random.Range(0, spawnPoints.Length)]; If you want to use both, there's no reason why you can't apply the position randomisation *after* having chosen a spawnPoint!

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>