• 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 threedollarbill · May 13, 2015 at 12:44 PM · physicsvelocityforce

Setting the velocity directly vs adding an IMPULSE force

Is there a difference between the two?

Setting the velocity directly:

 theRigidBody.velocity = transform.forward * velocityMultiplier;

Adding IMPULSE force:

 theRigidBody.AddForce(transform.forward * velocityMultiplier, ForceMode.Impulse);


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
3
Best Answer

Answer by Baste · May 13, 2015 at 03:17 PM

setting force directly cancels out all other force, while AddForce adds the force.

So with this code:

 theRigidBody.velocity = transform.forward * velocityMultiplier;
 theRigidBody.velocity = -transform.forward * velocityMultiplier;

ends you up with the velocity from the second line. This code, on the other hand:

 theRigidBody.AddForce(transform.forward * velocityMultiplier, ForceMode.Impulse);
 theRigidBody.AddForce(-transform.forward * velocityMultiplier, ForceMode.Impulse);

should end you up with zero velocity.

Note that ForceMode.Impulse also takes the mass of the rigidbody into account. See this page for what the ForceModes does. In theory, if the object is at a standstill, using AddForce with Forcemode.VelocityChange should be exactly the same as setting velocity.

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 threedollarbill · May 14, 2015 at 12:19 PM 0
Share

cool cool thanks!

avatar image CaseyHofland · Jun 09, 2019 at 11:19 PM 1
Share

Another very, 'very' small difference I came across was that the velocity of the rigidbody does not agree with its actual velocity when using AddForce, the frame you set it.

 rigidbody.velocity = Vector3.up * 100f;
 Debug.Log(rigidbody.velocity);
 // Logs (0.0, 100.0, 0.0)

 rigidbody.AddForce(Vector3.up * 100f, Force$$anonymous$$ode.Impulse);
 Debug.Log(rigidbody.velocity);
 // Logs (0.0, 0.0, 0.0);

In practice, this is almost never a problem, unless you are me and coincidentally need to make an accurate velocity check the frame you apply it.

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

21 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

Related Questions

Why does using a temporary variable break rigidbody? 1 Answer

Calculate velocity to set to reach a target point on a plane considering the drag. 0 Answers

how to get starting velocity of an object, which is thrown with a 45 degree angle and will pass some (x,y) point 0 Answers

Move gameobject at constant speed 1 Answer

Can I, someway, avoid centripetal force? 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