I've been trying out different methods for a shooting script to try and make it as versatile as possible.
I've decided on something like this:
public GameObject bullet;
public float bulletSpeed = 1000f;
private Rigidbody bulletRB;
void Update ()
{
if (Input.GetMouseButtonDown (0))
{
GameObject.Instantiate (bullet, this.transform.position, this.transform.rotation);
bulletRB = bullet.GetComponent ();
bulletRB.AddForce (this.transform.forward * bulletSpeed);
}
}
But when the object is created it just falls without any force. I know it has something to do with how I'm applying the force, but I can't figure it out. Any help would be awesome!
↧