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

AddForce not working on instantiated bullets

$
0
0
I'm trying to make a 2D shooter, the ship constantly looks at the mouse cursor and should fire with left click. Right now I have public GameObject bullet // The prefab float nextFire; void Update () { // Movement Code // Rotation Code // Shooting if (Input.GetMouseButton(0) && Time.time > nextFire) { nextFire = Time.time + 0.1f; GameObject bulletInstance = (GameObject)Instantiate(bullet, transform.position, transform.rotation); bulletInstance.GetComponent().AddForce(transform.forward * 8000); } } The ship is able to fire bullets, but they don't move. The prefab already has a rigidbody2D and the code compiles smoothly.

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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