On the way - to play with the forces!
"There was a time when he was happy when things just worked. It did not matter how is it possible. It was just enough it worked. But these times are over. Sometimes it brings him a headache trying to undrestand everything but till it is mostly rewarding hobby it does not matter. For what he love the sacrifices has to be done"
After the section "Awesome platformer" of the course I have been doing these last couple days I had to check what are the differencies in applying different ways to move the objects. Otherwise I bet it would drive me mad.
I was exploring a rigid body and possible ways to move object with this component - namely by:
If you would multiply the VelocityChange by Time.fixedDeltaTime you would get Acceleration, same for Implus and Force. Therefore I think that "over time" in unity means that it simply divide the velocity by frame rate.
What I still dont understand is how Acceleration and Force are influenced by gravity of rigid body. Because when the method AddForce(new Vector3f(1,0,0)) is used on rigid body with gravity it does not move at all but when the gravity is turned off it moves. If you know, share! Sharing is caring.
UPDATE [2019-11-08]: After conversation with my colleagues the idea of solution pop uped in my head. If I would only listen to me all knowing partner I would come up with solution right away. Do you remember the sticky walls from Awesome Martio grand finale post? Well, it was same situation over here. It looks like opossite force of both colliders caused the cubes not to move at all. After adding Physics material with no friction it moved, yay! :)
The last imporant thing to compare the three approaches is that Addforce() does exatly what is written in the name of the method - it is ADDing the force to the velocity. I will explain why I had to state this obvious fact in the second point.
After the section "Awesome platformer" of the course I have been doing these last couple days I had to check what are the differencies in applying different ways to move the objects. Otherwise I bet it would drive me mad.
I was exploring a rigid body and possible ways to move object with this component - namely by:
- Using method rigidbody.AddForce() and its ForceModes
- Updating rigidbody.velocity
- Using method rigidbody.transform.Translate()
For the purpose of next text we are going to assume that all ways to move object are applied inside the FixedUpdate() method without any futher limitation. You may wonder why FixedUpdate() - well, all physics should go to the FixedUpdate() since it is in sync with physical computation of Unity.
Using the force
The 4 modes for AddForce are Impulse, Force - both dealing with the mass and Acceleration and VelocityChange - both ignoring the mass. It was grouped from the point of view of applying mass but you could also grouped it from the point of view of force speed application (hope it makes sense :-D) . It means that Impuls and VelocityChange are applied in the full force instantly like if you kick a ball therefore Acceleration and Force are applied over time like if you start moving a car (you do not move at 50 km/h instantly).If you would multiply the VelocityChange by Time.fixedDeltaTime you would get Acceleration, same for Implus and Force. Therefore I think that "over time" in unity means that it simply divide the velocity by frame rate.
| pic.1 - illustration of force speed application |
What I still dont understand is how Acceleration and Force are influenced by gravity of rigid body. Because when the method AddForce(new Vector3f(1,0,0)) is used on rigid body with gravity it does not move at all but when the gravity is turned off it moves. If you know, share! Sharing is caring.
UPDATE [2019-11-08]: After conversation with my colleagues the idea of solution pop uped in my head. If I would only listen to me all knowing partner I would come up with solution right away. Do you remember the sticky walls from Awesome Martio grand finale post? Well, it was same situation over here. It looks like opossite force of both colliders caused the cubes not to move at all. After adding Physics material with no friction it moved, yay! :)
The last imporant thing to compare the three approaches is that Addforce() does exatly what is written in the name of the method - it is ADDing the force to the velocity. I will explain why I had to state this obvious fact in the second point.
Using the velocity
If you are going to use the rigidbody.velocity = new Vector3(1,0,0) the change would be 1 unit per each second. There is the difference between adding force and assigning the velocity directly. AddForce will add force to velocity, so if it was before (1,0,0) and you are going to add (1,0,0) it is going to become (2,0,0) therefore when you assigned the velocity it will remain (1,0,0). I know, obvisous, right? That is why there is not even single question about it on unity forums, stackoverflow and etc.(wink, wink).
Using the translate
Well and by using the rigidbody.transform.translate(new Vector3(1,0,0)) you would move the object by (1 * frame per second) units per second. If you would want to move it just by 1 unit per second you can multiply it by Time.fixedDeltaTime and you will get the same result as with the previous rigidbody.velocity = new Vector3(1,0,0).
Time spent on learning [29:16:47] - and guess what?! Those 47 seconds are especially important!

Comments
Post a Comment