Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

I need help with a firing script 1 Answer

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

ammo display javascript 1 Answer

How to let my gun shoot ?? 0 Answers

Gun Firing help? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges