- Home /
Gun not firing in certain direction
Hello,
So I have my weapon firing but it fires in a forward direction. The gameobject points in the direction I want to fire it but it only goes straight. What am I missing to making the bullet shoot in the direction it faces.
scatterBullet = Instantiate(scatterBulletPrefab, this.transform.position, Quaternion.identity) as GameObject;
scatterBullet.transform.parent = scatterBulletContainer.transform;
scatterBullet.transform.Rotate(new Vector3(0,0,bulletAngle));
scatterBullet.rigidbody.velocity = (transform.up * 500);
Thank you very much for any help.
Comment
Best Answer
Answer by robhuhn · Aug 26, 2013 at 06:59 AM
If I understand it correctly you already rotated the bullet to the desired angle bulletAngle. So if you only need the bullet to go straight forward in local space use:
scatterBullet.rigidbody.AddForce(scatterBullet.transform.forward * 500f);
oh snap, i just realized. I'm using the transform.up on the plane, so ofc its always going to move straight upwards from the plane. Thanks for point out my mistake! I'll accept the answer when I can test this and know for sure but you seem absolutely correct robhuhn.