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 Nikes · Mar 05, 2015 at 11:07 AM · c#rigidbodyweaponframedrop

How to use rigidbody.AddForce in a single frame.

Hi guys, I'm making a gun drop away from the player but when I apply the rigidbody.Addforce on it, it doesnt stop moving, I have everything working fine, the possible solution is to make the "AddForce" works like when we call it on "void Start () {}", I just dont understand why it still updating the command even if I close it in a simple "If"

I'm using "rigidbody.AddForce (transform.forward * 20);"

I already tried to use a coroutine to fix my problem:

 public IEnumerator ThrowWeapon()
     {
         Weapon.rigidbody.AddForce  (transform.forward * 20f);
         yield return new WaitForSeconds(0.25f);
         Weapon.rigidbody.AddForce  (transform.forward * -20f);
     }

this works almost fine, the only problem is that the object never sleep, and I dont want to waste memory

I feel like I'm forgetting something, maybe I'm just tired. if I find a solution I post here, Peace off.

SOLUTION:

I had to make a condition to the object so when its touching the ground I call rigidbody.velocity = Vector3.zero, it was effective, and the transform of the object in the inspector stopped as I wanted, I didnt use the rigidbody.AddForce in a single frame but at least I could solve my main problem.

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 WillNode · Mar 05, 2015 at 11:51 AM 0
Share

wait a second, you said that the object are never sleep, does it meaning that the object are always moving and never stop?

avatar image Nikes · Mar 05, 2015 at 05:23 PM 0
Share

Yes, the transform of the object in the inspector doesnt sleep, as it was receiving force yet, I just wanted to break that, this doesnt happen if I put my function in the "void start(){}", cuz the force is applied in the first frame, and you know its a gun dropping action, I should be able to do that whenever I want.

avatar image Nikes · Mar 05, 2015 at 06:38 PM 0
Share

Thanks hexagonius I used what you said to make the rigidbody stop and it worked, finally my object stopped shaking in the ground.

avatar image meat5000 ♦ · Mar 05, 2015 at 07:36 PM 0
Share

Click the tick to accept the answer

2 Replies

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

Answer by hexagonius · Mar 05, 2015 at 05:36 PM

Is the object even coming to a rest? (lying still)

Did you apply a PhysicsMaterial to the gun that has friction? (makes it stop by itself)

If its just one gun forget about the performance

If you want the rigidbody to "STOP" call rigidbody.velocity = Vector3.zero on it.

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 DrBibop · Feb 20, 2016 at 10:05 AM

@Nikes You could also use an Impulse force instead of a constant one (if I understand what you are trying to do). You can add "ForceMode.Impulse" to your line :

      Weapon.rigidbody.AddForce  (transform.forward * 20f, ForceMode.Impulse);

If you do so, I think the two other lines would be useless.

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

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

My script for pick up items work is wrong! Help please 1 Answer

In need of help with OnTriggerEnter 0 Answers

How do I control the speed of a rotating rigidbody? 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