First of all, sorry for my english…
However, i’m learning gamedev due the online courses. At the moment codding according “2D Character Controllers” and i have one little problem. So, when my rigidbody falls down and riches the collider it gets velocity 0, but after few frames it gets non-zero speed and after again zero. If i log out the rigidbody.velocity.y (= speed) i get it :
Question is: how or why the RigidBody gets that -2.443569E-08 velocity (i’m doing nothing at that moment) and how can i solve it?
-2.443569E-08 is, for all intents and purposes, equal to 0. A difference that tiny is unavoidable with floating point calculations, and should never make a difference to your game anyway. Simply ignore it and move on.
Tilemap Collider add Composite Collider property;
Offset Distance value edit value to 0
That number is pretty much equal to zero. Floating point variables can sometimes get small errors like that, due to the way values are converted between decimal and binary.
If this is a real stopper for you, don’t use
if (variable == 0.0f)
to check it, use:
if (Mathf.Approximately(variable, 0.0f))
if (variable <= .000001f)
When you use 2D Physic, Gravity set on y axis by default. So velocity of each
Rigidbody2D is effect by 2d gravity,
this could be the main reason for it, as I know unity never set any value to 0 which effect to physic, (like
Time.deltaTime which effect physic directly, when we set
Time.deltaTimeto 0 will stop all calculation as we know, but unity trick it very low amount like 0.00000001 which make minimal calculation to physic and we feel physic calculation stop)
so if you measuring something on
Rigidbody2D.velocity.y answer by @tasarran will perfect solution to identify velocity in y axis.