Difference Between Rigidbody.velocity and Rigidbody.addforce in Unity
Rigidbody Velocity and Rigidbody Addforce are two confusing functions in Unity 3D and often beginners fail to understand their difference. In This Article, I'm going to discuss the difference between RigidBody.velocity and RigidBody.addforce.
In both cases, whether it is Addforce or velocity function I'm am going to use the term force to explain them.
When you are using Rigidbody.velocity , then, in that case, you are adding force to your object but this force will only move the object unless and until we keep applying force.
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
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 .
A guy has also explained on unity forums about this what he says read that
First of all the difference is, rigidbody.velocity changes the velocity in an instant while AddForce applies force on an updated basis based on how you use it.Source is here
For example, in real world, when you kick the football, you apply a force to it but, it's a big force so ball's Z velocity suddenly becomes let's say 10. So from 0 it becomes 10 and it moves forward really fast, getting slower in time because of the air drag. Same applies for the drinks a barman tosses on the bar like in the movies.
When you push a very heavy create, you apply force to it constantly because it's very heavy and it has a bigger mass so it resists the force therefore moves slower. And you add more force constantly to move it somewhere.
When an attack helicopter shoots rockets, those rockets always move with the same speed because they have a constant pushing power behind them, or the space shuttles once they are taking off. So they don't lose speed. it's constant force.
So about which works best for which situations as it should be already clear from the above examples,
-Constant force for objects which have their own pushing power like rockets.
-Rigidbody.velocity for objects which have a big starting power then getting slower by drag, like football, thrown hand grenade, arrow etc. (I've also used this for making a jump pad. So that when player triggers the jump pad, players Y velocity suddenly becomes 10 so it jumps up getting slower in time)
-AddForce for adding forces constantly, moving objects with force every frame. If you know Marble Blast game, that's how it works. Based on the player input, you add a force to the marble. So as long as forward button is held down, a force of for example 5 added to it in that direction.
In this video, you'll see its practical implementation. This video is in Urdu / Hindi but just watch for practical knowledge.
This video Shows difference between RigidBody.addforce and Rigidbody.velocity in
Give your feedback in comment section and comment the topic whose tutorial you want