• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Tracey P · Mar 12, 2011 at 02:34 PM · javascriptfpsgungunfire

Is there a script out there that actully works for shooting bullets?

I am trying to make my guns fire bullets you know like guns do XD but the script that I am using dosnt work and I was wondering if anyone could help me fix it. I am using the newest version of Unity. code I have now:

var projectile : Rigidbody;

var initialSpeed = 20.0;

function Fire () {

var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);

instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));

Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider); }

function Update () { if (Input.GetButtonDown("Fire1")) { Fire(); } }

can someone please help solve this problem soon thank you for you help.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Mar 12, 2011 at 02:48 PM 0
Share

What is it that doesn't work? Could you please provide more information?

avatar image Scribe · Mar 12, 2011 at 05:11 PM 0
Share

just checking, have actually specified the rigidbody that you are instantiating in the inspector

avatar image Owen-Reynolds · Mar 12, 2011 at 05:30 PM 0
Share

Shouldn't you be firing the Transform that contains the rigidbody? I'd guess that you might be firing it (do you see a new GameObject pop up?) but it has no mesh, so you don't see anything.

avatar image Tracey P · Mar 12, 2011 at 05:43 PM 0
Share

The Bullet fires only one way if i turn left it fires right if I turn back it fires straight

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Tracey P · Mar 13, 2011 at 01:53 AM

Ok the script works now its the one I posted but now can someone help me make the bullets disappear after a time and show me how to attach a particle effect to it that folows the bullet along its path. Right now my attached particle system shows up but doesn't stay with the bullet as it runs its course it just stays in the same spot it spawned. All help is appreciated thank you.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FLASHDENMARK · Mar 13, 2011 at 10:59 AM 0
Share

var lifeTime = 2.0;

function Awake ()

Destroy(gameObject,lifeTime);

This will detroy the object the script is attatched to in 2 seconds.

avatar image Tracey P · Mar 13, 2011 at 08:51 PM 0
Share

Thanks do you have a solution to the particle problem too?

avatar image
0

Answer by efge · Mar 12, 2011 at 04:23 PM

Not shure why you use TransformDirection, but you could try this (or maybe better use Rigidbody.AddForce):

instantiatedProjectile.velocity = Vector3 (0, 0, initialSpeed);
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Mar 12, 2011 at 05:29 PM 0
Share

TransformDirection is correct. What you have fires the bullet North at all times. TransformDirection twists (0,0,initspeed) around to the direction the player is facing.

avatar image Tracey P · Mar 12, 2011 at 05:47 PM 0
Share

Still dosnt work even with this

avatar image Tracey P · Mar 12, 2011 at 06:17 PM 0
Share

works dont knw how but it does

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

FPS - Looking Down The Barrel 2 Answers

Need coding help with fps 0 Answers

I need help with a firing script 1 Answer

Need help... Start Button no longer working!!!!! 0 Answers

ammo display javascript 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges