Quantcast
Channel: Questions in topic: "random spawn"
Viewing all articles
Browse latest Browse all 125

How do I add force on an object(with a rigidbody) that I've randomly instantiated along the "Y" axis?

$
0
0
I know I need to use rigidbody.AddForce, But I'm having trouble finding how. This is what I have, but when I start the game, it spawns the object randomly but doesn't add and force to it. Any help would be greatly appreciated. var asteroid : Transform; var asteroidSpeed : float = -200.00; var spawnAsteroid : boolean = false; var ran1 : float; var transPos : float; function Update (){ if(spawnAsteroid == true){ if(Input.GetButtonDown("Jump")){ var Asteroid : Transform; asteroid = Instantiate(asteroid, transform.position, transform.rotation); asteroid.rigidbody.AddForce(transform.right * asteroidSpeed); } } }

Viewing all articles
Browse latest Browse all 125

Trending Articles



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