What exactly is ClampMagnitude?

Hey, I’ve been struggling to understand what this actually is, I’m watching a tutorial on joysticks and in the video simply by writing Vector3.ClampMagnitude he made the joystick square area into a circle.
Could anyone explain to me what it is?

1 Like

Vector3.ClampMagnitude. Should be pretty straight forward, but the simple version is that it ensures that the length of the vector (the “magnitude”) is no more than the given argument.

So if you clamp the magnitude of the vector (3, 0, 0) to 1.5, you’re going to get the vector (1.5, 0, 0). If you clamp (1, 0, 1) to the length 1, you’re going to get (Sqrt(0.5), 0, Sqrt(0.5)) because of Pythagoras. That’s about (0.7, 0, 0.7).

7 Likes

Thanks! now i get it.

1 Like