Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
4
Question by Juri · Nov 05, 2010 at 10:10 AM · rigidbodyaddforce

Rigidbody.addForce is not working

hey I am trying to make my character fire a bullit, i use this code to instantiate the bullit and add force to it! but some how the bullit is not getting move by the force!

   if(Input.GetButtonDown ("Fire2"))
        {
        var bullit = Instantiate (bullitPrefab, gameObject.FindWithTag      ("spawnPoint").transform.position,gameObject.FindWithTag("spawnPoint").transform.rotation); 
        bullit.rigidbody.AddForce(transform.forward * 200);
        }   

can u guys help me here?

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

10 Replies

· Add your reply
  • Sort: 
avatar image
12

Answer by Nilesh · Feb 20, 2012 at 12:36 PM

Try bullit.rigidbody.AddForce(transform.forward * 200,ForceMode.Impulse);

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 juicefoozle · Oct 24, 2015 at 07:03 AM 0
Share

i know, this is a couple of years ago. but i came here via google, and your Answer solved all my problems today! thanks.

avatar image karma0413 · Feb 04 at 12:56 AM 0
Share

7 years later, answer still valid. Who knew we needed to specify the ForceMode... Thanks!

avatar image
2

Answer by denewbie · Nov 06, 2010 at 04:14 PM

Does your "Gun" have a collider? If it does then the bullet collide with your "Gun" before it can ever fire out right...

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 Juri · Nov 06, 2010 at 05:22 PM 0
Share

It has a collider on it, but the spawn point of the bullet is far enough away from it. and shouldn't the bullet then at least move as soon as i move away from it??

avatar image denewbie · Nov 10, 2010 at 04:50 PM 0
Share

In that case may i just check of you that the bullet was spawned and not moving or it was never spawned at all?

avatar image
1

Answer by Loius · Nov 05, 2010 at 02:46 PM

Your bull*E*t object is missing a rigidbody or its rigidbody is kinematic. If that's not the problem you'll have to specify exactly what does happen when you press "Fire2".

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 Juri · Nov 05, 2010 at 08:14 PM 0
Share

ok i wrote bullet wrong, sorry about that :P but what do u mean by specify, the code should be right but it doesn't work.. so where is the mistake??

avatar image ImASquirrelYipee Juri · Aug 29, 2020 at 10:53 PM 0
Share

I know this is many years old, but what he meant is what happens when you press it, does it shoot you, does it not shoot, does it teleport somewhere.(just incase you need it for future)

avatar image
1

Answer by pjnovas · Sep 05, 2014 at 05:39 PM

I know this post is really old, but I came across the same problem and I realised the transform.forward is a Vector3.zero, it is at (0,0,0) because of your rotation.

So if you do a Vector3.zero * 200 is a Vector3.zero and adding a force of ZERO will do nothing.

I'm leaving this if someone else has the same thing.

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

Answer by WARW0LF · Dec 18, 2020 at 01:33 PM

I found this way works the best:

 Vector3 direction = Vector3.zero;
 direction = Vector3.forward * amtOfForce;
 rigidbody.AddForce(direction * Time.fixedDeltaTime, ForceMode.Acceleration);

use transform.forward if vector3.forward isn't right, your amtOfForce has to be really high, just for a jump i had to set my force float to 15000, this should be placed in a FixedUpdate if posible and always used Time.fixedDeltaTime for physics

hope this helps someone else wondering why addforce doesn't work

Comment
Add comment · 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
  • 1
  • 2
  • ›

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

12 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

Related Questions

Keep gravity while adding velocity to a Rigidbody? 1 Answer

rigidbody,addforce is affecting all clones which are clicked on through raycast 0 Answers

How to remove addforce effect 0 Answers

How to make Airplane move forward faster INSTANTANEOUSLY? 1 Answer

Ello~ I need help with transform.parent = null; When I play it and press the DropWeapon input button it goes in a random location and doesnt move . 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