Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Random instantiate at same frame with each instantiate having unique random direction

$
0
0
Hello! This question should be rather short (and sweet!). I have an enemy type in my game dropping a random set of coins Range(1,10). Problem is, they all go the same way for my "coin.rigidbody2D.AddRelativeForce(randomDirection);". I thought it would go through the for-loop differently each time. How do i go about making it so? private int numberOfCoins; void Start() { numberOfCoins = Random.Range(1,10); } void LateUpdate() { [...] Vector2 randomDirection = new Vector2(Random.Range(-800f, 800f), Random.Range(-800f, 800f)); GameObject coin; for (int i = 0; i < numberOfCoins; i++) { coin = (Instantiate(coinPrefab, enemy.transform.position, enemy.transform.rotation)) as GameObject; coin.rigidbody2D.AddRelativeForce(randomDirection); }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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