- Home /
*= Mathf.Min
What this does is times heldObject's velocity by Mathf.Min(1.0f, force.magnitude / 2). I'd like to know how Min works in this situation and why there is a = instead of just a . What does this line of code actually do?
heldObject.rigidbody.velocity *= Mathf.Min(1.0f, force.magnitude / 2)
Out of context, the 'whys' of this line of code are unclear. The effect is to say that if the force.magnitude is less than 2.0, the velocity will be multiplied by 1/2 the magnitude of the force and will result in a reduction of heldObject.rigidbody.velocity. Said another way, if the force is too small (below 2), the velocity will be scaled down.
Answer by stevethorne · Mar 07, 2014 at 10:00 PM
The min function in this example is merely enforcing a cap on the amount the velocity is multiplied by. It's multiplying the velocity by 1.0 or the magnitude of the force divided by 2; whichever one is smaller.
The = portion of this equation makes sure that the velocity is set to the velocity the min function.
If there were just a *, then it would multiply them, but it wouldn't set the velocity to it.
For example,
float x = 2;
x *= 3;
Is short for writing this:
float x = 2;
x = x * 3;
If you just write
float x = 2;
x * 3;
x wont be 6 in the end, it will still be 2.
Your answer
Follow this Question
Related Questions
Getting Turret to Fire on the Correct Top-Down Plane 0 Answers
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Kinematic how to know rigidbody velocity vector? 1 Answer
relative velocity of rigidbody according to rotation... 1 Answer
Velocity relative to Local Axis 1 Answer