• 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
1
Question by Vesmok · Dec 12, 2012 at 03:14 AM · rigidbodybulletjava

My bullet wont move forward

So my script wont work...

 var Bullet : Rigidbody;
  var Spawn : Transform;
  var BulletSpeed : float = 1000;
 
 
 function Start () {
  
 }
  function Update () {
  if(Input.GetButtonDown("Fire1")) {
  Fire();
  }
  }
  
 function Fire(){
  var bullet1 : Rigidbody = Instantiate(Bullet,Spawn.position,Spawn.rotation);
  bullet1.AddForce(transform.forward*BulletSpeed);
 
 }



the bullet is created but wont move!

Edit :

This image shows the Inspector settings : imgur.com/a/Ct16P

[1]: http://www.imgur.com/a/Ct16P

Comment
Add comment
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

1 Reply

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

Answer by clunk47 · Dec 12, 2012 at 04:36 AM

You didn't have your instantiation defined correctly. The new "bullet1" needs to be set as a "clone" pretty much. You just had var bullet1 : Rigidbody; then your instantiate command for Bullet. It needs to be var bullet1 = Instantiate(Bullet... Because when you were adding force to bullet1, it was null. It's also a good idea to disable gravity on this rigidbody since it's going to be used as a bullet. As well, set the collision detection to Continuous Dynamic if you want it to be able to detect such fast collisions. I just used mousebutton 0 (left click) here so I could test it ( I don't have Fire defined.) You actually may have had the first part set up right, the format on this site is making it show up wrong. But if you try this script, it will work.

 var Bullet : Rigidbody;
 var Spawn : Transform;
 var BulletSpeed : float = 1000;
 var fwd : Vector3;
 
 function Start () 
 {
 
 }
 
 function Update () 
 {
     fwd = transform.TransformDirection(Vector3.forward);
     if(Input.GetMouseButtonDown(0)) 
     {
         Fire();
     }
 }
 
 function Fire()
 {
        var bullet1 : Rigidbody;
        bullet1 = Instantiate(Bullet, Spawn.position, Spawn.rotation) as Rigidbody;
        bullet1.rigidbody.useGravity = false;
        bullet1.rigidbody.AddForce(fwd * BulletSpeed, ForceMode.Impulse);
 }

Comment
Add comment · Show 4 · 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 Vesmok · Dec 13, 2012 at 03:48 AM 1
Share

It works! thank you so much!!!!!

avatar image Vesmok · Dec 13, 2012 at 03:49 AM 1
Share

IS there any way i can upvote you or somthing? but thank you so much for the help! it worked

avatar image AlucardJay · Dec 13, 2012 at 03:55 AM 2
Share

Just some tips on using this 'site (for ALL new users) :

How to reply to an answer / post a comment :

To make a comment , USE the [add new comment] button, a window then opens to type in. The answer fields are for ANSWERS, so unless you are answering your own question , DON'T write in an answer box. This helps the 'site work properly, especially when other people are searching for answers, and want to read answers , not comments.

How to accept an answer :

On the left-hand-side of the Answer box , there are the following icons :

  Thumb Up
  Number (of votes)
  Thumb Down
  A Tick/check mark

If an answer worked for you , click on the 'Tick' , the answer should now be highlighted in green. If you like an answer on Any question , you can click on the Thumb UP , the thumb should now be highlighted in green , and the number of votes should rise by 1.

When your karma rises above 15, you can upvote any answer (on any question) you like or think is correct, this gives the person karma for their time and effort.

IF your question changes slightly while commenting and reading comments , EDIT the original Question, so anyone reading from the beginning knows what you are asking.

This will make for a happy experience for everyone. I made mistakes starting on this 'site too, but everyone is helpful if you learn and change these habits.

Following these simple steps helps the website work , and other readers to find answers also.

Happy Coding =]

the FAQ appears at the bottom of the page : http://answers.unity3d.com/page/faq.html

avatar image AlucardJay · Dec 13, 2012 at 03:57 AM 2
Share

I upvoted this answer =]

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Script in UNITY ??? 2 Answers

i need some code suggestions 1 Answer

Gun Script Error (Fixed!!!) 1 Answer

My bullet follows my plane... 1 Answer

Error in script 1 Answer


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