title: Making rigidbody magnitude constant in Unity
body: <p>I am trying to keep the magnitude of a rigidbody at a constant speed of 3.5. I don't want it lower or higher than that. </p>
  
  <p>Here's what I did so far in FixedUpdate()</p>
  
  <pre><code>        if(rb.velocity.magnitude &gt; 3.5f)
          {
              Debug.Log("ABOVE");
              rb.velocity = Vector2.ClampMagnitude(rb.velocity, 3.5f);
          }
          if(rb.velocity.magnitude &lt; 3.5f)
          {
              Debug.Log("BELOW");
              // Not sure if calculation below is correct
              rb.velocity = rb.velocity.normalized * 3.5f;
          }
  </code></pre>
  
  <p>I know I implemented the first <code>if</code> statement correctly (clamping if it is over 3.5). I've searched around online and this is what some people suggested when it comes to clamping the magnitude if it exceeds the desired limit.</p>
  
  <p>However, I'm not sure if I implemented the second <code>if</code> statement correctly (if the magnitude is lower than 3.5). I couldn't find any online posts/questions regarding this.</p>
  
  <p>My question is: what is the correct way of setting the rigidbody's velocity if it goes lower than the desired speed? I have tested that clamping only works if the value exceeds the limit.</p>
  
  <p>I want to keep the current direction, by the way. I just want to change/increase the speed. I'm not sure if using <code>normalized</code> is correct. </p>
  
  <p>Appreciate any help. Still a newbie with physics/math programming. </p>