x


Bullet still goes sideways...

I maded a script but still it doesn't work can someone help me please?

Here's the script:

var BulletPrefab:Transform; var force : float = 2000;

function Update() { if(Input.GetButtonDown("Fire1")) { var bullet = Instantiate(BulletPrefab,

GameObject.Find("Barrel").transform.position,

GameObject.Find("Revolver").transform.rotation);

bullet.rigidbody.AddForce(transform.forward * force);

} }

more ▼

asked Jul 20 '12 at 02:41 PM

tom1103 gravatar image

tom1103
-11 1 8 13

What do you mean by "it doesn't work"? Do you get compilation error? What do you expect your script to do?

Jul 20 '12 at 02:55 PM Kryptos
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You're using transform.forward as the force direction. The bullet will fly in the direction that the object that holds this script is facing, as opposed to the direction your revolver is facing.

What happens when you use:

bullet.rigidbody.AddForce(GameObject.Find("Revolver").transform.forward * force);

P.S. are you sure you don't want to use hitscan for a revolver? They move pretty fast.

more ▼

answered Jul 20 '12 at 04:04 PM

Muuskii gravatar image

Muuskii
1.2k 4 10

(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:

x2060
x461
x320
x55
x12

asked: Jul 20 '12 at 02:41 PM

Seen: 368 times

Last Updated: Jul 20 '12 at 04:04 PM