• 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 /
  • Help Room /
avatar image
0
Question by yvyv1000 · Oct 20, 2015 at 09:25 PM · movementaddforcebullet

bullet wont move forward

i have this script:

  var projectile : Rigidbody;
  var speed = 1;
  var barrel : Transform;
  var shots :  int  =  0 ;
  var maxShots :  int  =  1 ;
  var fwd : Vector3;
  
  function Update () {
      fwd = transform.TransformDirection(Vector3.forward);
  
  if ( Input.GetButtonDown ("Fire1") && shots < maxShots){
  
         var bullet1 : Rigidbody;
         bullet1 = Instantiate(projectile, barrel.position, barrel.rotation) as Rigidbody;
         bullet1.GetComponent(Rigidbody).useGravity = false;
         bullet1.GetComponent(Rigidbody).AddForce(fwd * speed, ForceMode.Impulse);
  shots ++;
  
  }
  else if (shots >= maxShots && Input.GetKeyDown(KeyCode.R))
      {
         Reload();
      }
  }
  
  function Reload() {
   yield WaitForSeconds(0.5); 
          shots = 0;
  }

it' s not 100% mine i used some parts of a tutorial but when i add the force my bullet will just float in the air where it is spawned can someone tell me whats wrong cause i honestly thing it should work but it' s probably something small

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

2 Replies

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

Answer by yvyv1000 · Oct 21, 2015 at 09:22 AM

i fixed my problem that kanematic shouldn' t be on but off so i changed and now it works its strange though cause unity actually can't do without it if you have mesh collider on so i changed it to sphere

Comment
Add comment · Show 1 · 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 yvyv1000 · Oct 21, 2015 at 09:30 AM 0
Share

changed it again ins$$anonymous$$d of the var fwd i now use transform.forward but still floating in the are doing nothing

avatar image
0

Answer by smallbit · Oct 21, 2015 at 04:48 AM

You are adding force of 1, If you didn't change the mass of rigidbody (which is 1 by default) you are adding way to small force to it. Try bigger values for your speed, and see what happens or alternatively decrease the mass of the bullet.

Also you can remove the code from update, there is no need to run it every frame.

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 yvyv1000 · Oct 21, 2015 at 09:16 AM 0
Share

i already changed the speed value in the editor to 100 still no change

avatar image yvyv1000 · Oct 21, 2015 at 09:20 AM 0
Share

also it needs to be in update in order to shoot after it cause as you can see the shoot is triggered when i press the "Fire1" button so if i put it in start i can' t use it anymore i tryed but then the bullet won' t even appear

avatar image yvyv1000 · Oct 21, 2015 at 09:32 AM 0
Share

i need to add that my projectile is not using gravity and it is kanematic

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

32 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to move an Instantiated Object towards a moving Object? 0 Answers

2D Top-Down Character: How to make my character move using physics? 1 Answer

Car game and simple drift system with rigidbody.velocity 1 Answer

So this is the script and I want to be able to boost my speed with a press of a button for example "Jump",Can't increase my movement with GetbuttonDown 0 Answers

Using rb.velocity and Add Force on the same gameobject? 0 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