x


Bullet Fire script not working

Im making a mulitplayer shooter and when i shoot it fires out of the barrel using the spawnpoint i made but then it shoots really fast out of another location please help!

EDIT!!!! i tried changing the code to getbuttondown but it still fires out of the barrel plus the mag!

This is my code:

var projectile : Rigidbody;

var speed = 20;

function Update () {

if ( Input.GetButton ("Fire1")) {

clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));

Destroy (clone.gameObject, 2);

}}
more ▼

asked May 25 '11 at 03:54 PM

buildman99 gravatar image

buildman99
16 6 7 8

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

A few points (will look at it more if none of these work): 1. Is the script applied to the gun? If not, do so. If it is, try using transform.position + Vector3(Insert Length of the barrel / 2). This will make it come out of the end. Or you could just have an empty gameObject at the end of your barrel. 2. Try putting var before the first clone perhaps? 3. I'd be tempted to use GetButtonDown instead of GetButton, if you want the player to click for each shot.

more ▼

answered May 25 '11 at 05:24 PM

Muzz5 gravatar image

Muzz5
1.2k 64 83 94

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3322
x1172
x796
x681
x308

asked: May 25 '11 at 03:54 PM

Seen: 1467 times

Last Updated: May 25 '11 at 06:51 PM