- Home /
Bullet shots direction player is facing, cant shoot in diagnal or up
hi, here is my bullet script
var Bullet : Transform; var ROF = 10.0; // Rate of fire in bullets/sec. private var timeout = 0.0;
function Update () { if (Input.GetButton ("Fire1") && Time.time >= timeout){ var bullet = Instantiate(Bullet,GameObject.Find("BulletSpawn").transform.position,Quaternion.identity); bullet.rigidbody.AddForce(transform.forward *1000); Destroy(bullet.gameObject, 2); timeout = Time.time + 1.0/ROF; } }
when I shoot, it will shoot the direction that im facing. so i can do a compleat circle and shoot fine. but when I shoot at an upward angle, the bullets go parallel to the ground. what should i do. i also get a error message saying
UnassignedReferenceExceprion: The variable Bullet of 'Shooting script' has not been assigned. but in the inspector, it is assigned. thanks for your time
Please format your code properly. Use the "10101" button.
When you say "shoot up" are you talking about positioning the mouse in the upper half of the screen when you click? The mouse position is NOT related to transform.forward on whichever GameObject this script gets attached to.
Answer by Fabkins · May 17, 2011 at 05:26 PM
I assume "BulletSpawn" is at the end of your gun. If "BulletSpawn" is attached to character that is animated then I would expect this to work.
If however "BulletSpawn" is just a fixed position against the the player controller then it will fire at the same plane as the player controller.
I guess a quick experiment would be to replace "BulletSpawn" to whatever the camera is called. In theory then you should fire in the same direction that you are viewing.
Not an expert so appologies if this answer is incorrect but something to try.
Answer by Ninjaoboy · Jun 24, 2011 at 06:57 PM
is the spawn attached to your camera so that if you look up the spawn will be there too.
Your answer
Follow this Question
Related Questions
Shoot second cell in 2d 0 Answers
Animation Play On Bullet Shot 1 Answer
Problem with child position 0 Answers
Converting Direction Vectors In Children Manually 0 Answers
Object hold and mouse roll 1 Answer