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 /
avatar image
6
Question by GalZohar · Dec 05, 2012 at 12:47 AM · physicsvelocityaddforce

Why use AddForce rather than modify velocity?

I've looked all over, and while I've seen comments about modifying rigidbody.velocity being a bad idea, I haven't really noticed why. Assuming the velocity change is calculated properly, is there any difference between using it and using addForce?

If I add a force that will result in a velocity change of 1, or simply modify the velocity by 1, is there any difference in what actually happens in terms of gameplay and/or performance?

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

4 Replies

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

Answer by Bunny83 · Dec 05, 2012 at 12:57 AM

No, there's no difference. AddForce has actually different modes:

http://docs.unity3d.com/Documentation/ScriptReference/ForceMode.html

They all result in an immediate velocity change, but with a different scale.

Force and Impulse are divided by the objects mass, acceleration and velocitychange are not.

Force(`m*kg/s²`) and acceleration(`m/s²`) are computed so the value represents a change per second when applied every physics frame (in FixedUpdate). Velocitychange and Impulse are in `Δm/s` or `Δm*kg/s`

This all assumes the guideline that mass is in kg and 1 unit is 1 meter.

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
5

Answer by Iammnhamza · Sep 02, 2017 at 01:21 PM

Rigidbody Velocity and Rigidbody Addforce are two confusing functions in Unity 3D and often beginners fail to understand their difference. In This Article, we are going to discuss the difference between RigidBody.velocity and RigidBody.addforce.

In both cases, whether it is Addforce or velocity function we are going to use the term force to explain them.

When we are using Rigidbody.velocity , then, in that case, we are adding force to our object but this force will only move the object unless and until we keep applying force.

For example

body.velocity= new Vector3(0,0,5);

Let say you have added 5f in z position and that force will be added when you'll press W key. So When you will press W key the object will instantly start at the speed of 5. It's like the same if you are adding force using this function on a car, that car will start at the speed of 5.

body.velocity= new Vector3(0,0,200);

And if you let say change the value to 200 and then after saving press W. Car will start running at the speed of 200 from starting which is not possible in real world.

Now If you talk about Rigidbody.addforce

By Continuing our Car example. if you add the force of 200 to car

body.addforce(0,0,200);

The Car will not start moving at the speed of 200 if we press W but it starts from slow and then increases its speeds and stops according to the value of Drag.

Rigidbody.addforce starts slow and then speed up, just like you are dragging a heavy table, first you will start pushing that table, the table will just move a little bit from its position but if you keep pushing that table it will starting moving & if you leave that table it will cover some distance depending on surface and that's the same rigidbody.addforce do.

You can use Rigidbody.velocity where you just want to move your object to react instantly like player jump & the result of that force will vanish just after the jump and you can use Rigidbody.addforce where you need slow start and then the continuous movement like a rocket. If you use Rigidbody.addforce in jump , Player/Object will remain in space for a while and then will come back to ground .

For more with video visit here

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 Owen-Reynolds · Sep 02, 2017 at 01:50 PM 0
Share

You're confusing a 1-time change with a change over time, and also confusing = and += for velocity.

Using velocity+= every frame is the same as using AddForce every frame - gradually increasing speed. But you can use a 1-time large AddForce to instantly change speed to a large value. The 200 vs. 5 is merely due to the default addforce mode, which divides inputs by about 60, just because (see various Qs over the forcemodes.)

avatar image Iammnhamza Owen-Reynolds · Sep 02, 2017 at 05:57 PM 1
Share

that's how i understand that difference . Its my point of view :)

avatar image
-4

Answer by Janibasha · Nov 27, 2018 at 08:51 AM

Rigidbody Velocity and Rigidbody Addforce are two confusing functions in Unity 3D and often beginners fail to understand their difference. In This Article, we are going to discuss the difference between RigidBody.velocity and RigidBody.addforce.

In both cases, whether it is Addforce or velocity function we are going to use the term force to explain them.

When we are using Rigidbody.velocity , then, in that case, we are adding force to our object but this force will only move the object unless and until we keep applying force.

For example

body.velocity= new Vector3(0,0,5);

Let say you have added 5f in z position and that force will be added when you'll press W key. So When you will press W key the object will instantly start at the speed of 5. It's like the same if you are adding force using this function on a car, that car will start at the speed of 5.

body.velocity= new Vector3(0,0,200);

And if you let say change the value to 200 and then after saving press W. Car will start running at the speed of 200 from starting which is not possible in real world.

Now If you talk about Rigidbody.addforce

By Continuing our Car example. if you add the force of 200 to car

body.addforce(0,0,200);

The Car will not start moving at the speed of 200 if we press W but it starts from slow and then increases its speeds and stops according to the value of Drag.

Rigidbody.addforce starts slow and then speed up, just like you are dragging a heavy table, first you will start pushing that table, the table will just move a little bit from its position but if you keep pushing that table it will starting moving & if you leave that table it will cover some distance depending on surface and that's the same rigidbody.addforce do.

You can use Rigidbody.velocity where you just want to move your object to react instantly like player jump & the result of that force will vanish just after the jump and you can use Rigidbody.addforce where you need slow start and then the continuous movement like a rocket. If you use Rigidbody.addforce in jump , Player/Object will remain in space for a while and then will come back to ground .

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 Owen-Reynolds · Nov 27, 2018 at 02:43 PM 2
Share

This is plagiarized from $$anonymous$$ Numan Hamza on StackExchange. It's also wrong -- +=velocity can easily be used for a gradual increase.

avatar image kez1304 · Apr 16, 2019 at 11:12 PM 0
Share

"+=velocity can easily be used for a gradual increase." -- While true, this is handled by the programmer in a script. It's not the fundamental difference between the two. I can write a transform algorithm to act like either velocity or addforce, but that's really beside the point.

avatar image Owen-Reynolds kez1304 · Apr 17, 2019 at 12:29 AM 1
Share

Read Bunny's answer. There isn't a fundamental difference between the two. That's the whole point. But they're different from directly changing transform. AddForce/velocity uses the physics system, which makes the object move automatically.

avatar image
0
Wiki

Answer by mmcguffi · Dec 05, 2012 at 01:28 AM

one thing i can think of is that modifying the velocity would instantaneously set that velocity yea?

i suppose you would achieve a similar effect if the object in question was as rest, but if you were to apply this to a moving object per se, addforce would have to oppose the other force first while velocity would just immediately change it

tl;dr addforce would display more accurate physics

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 Bunny83 · Dec 05, 2012 at 01:34 AM 2
Share

It actually makes no difference. The Rigidbody has only those state variables:

velocity, angularVelocity and position, rotation (which are shared with the transform). No other state information is saved in the Rigidbody. All actions are immediately applied to those values. So AddForceAtPosition for example can affect all 4 at the same time.

avatar image Owen-Reynolds · Sep 02, 2017 at 02:11 PM 0
Share

Actually, this is true. velocity change is instant, code-wise, but AddForce isn't. See http://answers.unity3d.com/questions/800443/why-does-writing-to-rigidbodyvelocity-after-addfor.html. Skip my partly-wrong answer (even though it's green, which means nothing here) and go to Bored$$anonymous$$ormon and Chris'.

But one thing to try, is have a Cube race using the same velocity and AddForce's. I'd guess it's still a tie.

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

15 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

Related Questions

Accelerate a rigidbody towards max speed 2 Answers

How to calculate GameObject's velocity from AddForce. 0 Answers

AddForce vs Velocity issues with Rigidbody2D 2 Answers

Game running at different speeds on different quality levels. 1 Answer

Correcting Directional velocity for a plane 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