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

Creating a prefab and moving in a random direction - coin fountain burst

$
0
0
I'm trying to create a coin fountain burst. I saw several people asking questions related to this but I can't seem to get it to work. What I've done is: public void CreateCoinBurst() { for (int i = 0; i < numberOfCoins; i++) { Rigidbody coinInstance = Instantiate(coinPrefab, spawner.position, spawner.rotation) as Rigidbody; coinInstance.transform.rotation = Quaternion.Euler(Random.Range(0, 360), Random.Range(0, 360), 0);//This causes the coin to rotate around itself Vector3 direction = new Vector3(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360)); Debug.Log("dir: " + direction.ToString()); coinInstance.AddForce(direction * force, ForceMode.Impulse); } } The coins always shot in the same general direction and not really in a random direction. I have also tried: Vector3 direction = new Vector3(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360)); with different angles but all result in the coins poping in the same general direction. What am I missing?

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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