How exactly is AddForce Impulse calculated?

Hey there all, I’m having a bit of a problem that I have been trying to figure out for the last ~5 days, basically, I want an object to move by a specific amount using AddForce, for example, lets say 1 unit, however, when I use this snippet of code body.AddForce(new Vector3(1,0,0), ForceMode.Impulse); instead of moving it by 1 unit, so that the position is 1,0,0 It moves it by 0.03291207,0,0 so I realized that there is a calculation here, so I thought maybe for every 1 velocity, it moves it by 0.0329…, so I figured if I were to multiply the velocity by around 30, however, if I put body.AddForce(new Vector3(30,0,0), ForceMode.Impulse);, but now it moves it by 37.92695,0,0 , so I was really confused. So after making a spreadsheet and then copying and pasting different velocities and how they work, I finally figured it out. so it works a something a bit like this :

basically, there are 3 things, the input value [which we will call X], the velocity, and the position. the Velocity starts outs as the X, and every frame its decreased by - 0.2355

the position starts out as whatever position it is, and then there is a speed value, lets call it Y, now Y starts out as X divided by 100 and multiplied by 2, so for example if X is 1, Y would start out as 0.02, then, ~0.0048 is removed from Y, so now it’s 0.0152, and then every frame, the position is increased by the Y value, and also every frame, Y is being decreased by ~0.0048, ~0.0048 being the friction [I think].

and now that I knew how it worked, I could reverse engineer, and I did! so I figured out that to get the object to move by 1 unit, I needed to input around 5.02 velocity. So, you might be wondering if I figured it out, why am I posting it here? well, the problem arises when I try to move it on the Z-axis at the same time, like body.AddForce(new Vector3(1,0,1), ForceMode.Impulse); now it moves it by on both axis by 0.0500636, 0, 0.0500636 instead of 0.03291207,0,0.03291207. So this really made me confused, so then I made a spreadsheet and then copied and pasted different velocities and how they work. And it turns out the formula is still the same, however, 0.2355 and 0.0048 are changed, for example when it’s body.AddForce(new Vector3(1,0,1), ForceMode.Impulse);, 0.0048 is actually 0.00332966 so Y is being decreased by 0.00332966 every frame, but if there are 2 different numbers, then, they both have different 0.0048’s, for example, if it’s body.AddForce(new Vector3(1,0,2), ForceMode.Impulse);. for 1 the value is 0.00210584 meaning Y gets decreased by 0.00210584 every frame, but for 2 in the same vector, 0.00421168 is the magic number, meaning Y is decreased by 0.00421168 every frame.
And that’s where I’m stuck, I can’t figure out where these numbers are coming from. I tried dividing it, multiplying it, subtracting and adding and I just cant figure it out. So I would really appreciate help from the physics experts here. Keep in mind that I don’t know that much about physics and only know a bit about algebra and stuff like that, so I have no idea what the correlations are. If anyone needs it, here is the table I made showcasing every “magic number” from 1 to 6, the colored squares are squares that are quite similar[ICODE][/ICODE]

Sorry if this post was a bit confusing, this whole topic is a bit confusing so I’m not sure if I explained it well enough, and I’m a bit tired, so if you didn’t understand anything just leave a comment and I will try to answer it, Thanks in advance for any help :slight_smile:

1 Like

Hi
I could not read you whole thread but from the first part i understood your problem. I hope this will help.
It seems like you don’t realy know what force is. So if you are working on a project that is based on physics you should start learning newton physics (high school). If you want to move your rigidbody by one unit you should use the method rigidbody.MovePosition(Vector3 force).
This moves the rigidbody position to the input vector you have given it.

Now you have used impulse force so let me explain it to you. we have a variable called momentum (Symbol P) in physics which is equal to the product of Mass and Velocity.
P = M.V

Now when you set the forcemode.impulse you are adding that value to the objects momentum. this results in an immediate change in the objects velocity.
Example:
Let’s say you have a rigidbody with mass 5kg that is initially at rest.
Now you run the following code:rigidbody.AddForce(Vector3.forward, ForceMode.Impulse);
We know that Vector3.forward = (0,0,1).
So by that we mean that the change in our momentum is:
P = (0,0,1)
Now we put this in equation to find the result velocity.
(0,0,1) = 5 . V
V = (0,0,0.2)
Now our rigidbody is moving with the speed of 0.2 m/s in the Z direction.

2 Likes

First of all, I want to thank you for taking your time and posting this post, I really appreciate it,:slight_smile: anyway, I wanted to say, the problem with rigid body.MovePosition is that it just snaps, and it doesn’t move smoothly like rigid body.AddForce does. and there isn’t that much physics in my project, it’s just that ima bit stuck on one single physics aspect of my project but:p I probably will at some point learn more about physics. Anyway, thank you for that information, however, what I am interested in is how is drag/friction calculated? for example, if I turn off the gravity, then your thesis is true; the object moves 0.2 meters every second [which I think is about 50 frames in unity], however if i turn on gravity everything is messed up, for example if i put the force to be 0,0,1 it doesnt even reach 50 frames, if i put the force to be something that does reach 50 frames, for example, 500 force, then at 50 frames [1 second] it moved by 85.12633, however if it put 500, 0, 500 then at 50 frames instead of 85.12633 it moves by 86.55384. So this is all very confusing, I will probably have to do more research on the subject, but still thanks for responding :slight_smile:

1 Like

Thanks
If you want your rigidbody to move smoothly you can use a combination of rigidbody.MovePosition and IEnumerator interface to move it in a prriod of time.
The friction force is calculated by multiplying The coefficient of friction and the normal force created by that object and it is opposite the velocity vector of the object.
I hope this works for you

That sounds like the thing I need! :smile:, only I’m a bit new and hence confused to these terms like coefficient of friction, and normal force created by the object, and the opposite velocity vector object, so If you don’t mind, could you provide a example of this? say I would add a force of 1,0,1. What would the friction be?

Lets assume we have a rigidbody of mass 3kg and coefficient of friction 0.4.
The normal force is the force that the object is exerting on the ground. In this case it is equal to the weight of our rigidbody.
W = 3 X 9.81
W = 29.43
Now the friction force is calculated by multiplying the normal force and coefficient of friction.
friction = 29.43 X 0.4
friction = 11.772
It means that the minimum force that we to move that object is 11.772 Newtons.
So your force vector could be (11.772,0,0)
Or (0,0,11.772) or anything else.
However this could really get much more complex in 3D space. You should start learning high school physics then you can move into 3D space. however if you want your object to accelerate you need add a little bit more force like 11.8 for your object to start moving.:slight_smile:

1 Like