 # PLease can somebody explaine me more this concept

I really try understand this code but am still unsure.
Mathf.Abs = absolute value = positive. (from -1 do 1)
Mathf.Epsilon = minimum value close to zero = positive value.

so if my (absolute) rigidbody.velocity.x = positive (probably 1) > 0.0000000001 = its true = running
else (rigidbody.velocity.x( = 0) > 000000000.1) = its false = stop running

If my player going to the left = -x (absolute = +x) = running because absolute do from -x (+x)

Can somebody tell me if i understand this code or concept correctly ?

Hi Pechy6,

Yes, I think you understood this correctly. The reason behind this solution is that the physics simulation does not always return exactly 0f even if the game object does not seem to be moving. If we checked against exactly 0f, the ‘non-moving’ character might be ‘running’ while he is actually supposed to be ‘idling’. That’s why we use a threshold to define when something ‘is moving’ and when something ‘is not moving’. It’s a definition.

For simplicity, we use Mathf.Epsilon but we could have defined our own hard-coded value like in your explanation.

Why do we check against the absolut value? For simplicity. The alternative would have been a two-part condition:

``````if (myRigidbody.velocity.x < -0.0000001f || myRigidbody.velocity.x > 0.0000001f) { }
// if (myRigidbody.velocity.x < -Mathf.Epsilon || myRigidbody.velocity.x > Mathf.Epsilon) { }
``````

It’s longer and less readable, isn’t it?

If that’s what you understood, you understood the concept and the code. 