"No appropriate version" error

Hello! Using the default “thirdpersoncontroller.js” script that’s packaged with Unity, I’m attempting to add a “clamp” to the in-air velocity of the character. I’m very very new to scripting so please bear with me. I’ve researched this issue and often the solution is changing a capital letter here or there, but trying that for myself has proved fruitless.

I’m getting the error: Assets/Scripts/ThirdPersonController.js(175,28): BCE0023: No appropriate version of ‘UnityEngine.Mathf.Clamp’ for the argument list ‘(UnityEngine.Vector3, int, float)’ was found.

The lines in question are:

{// Lock camera while in air
	if (jumping) lockCameraTimer = 0.0;
	if (isMoving)inAirVelocity += targetDirection.normalized * Time.deltaTime * inAirControlAcceleration;
	Mathf.Clamp(inAirVelocity, 0, walkSpeed);

The code is all default except for the last line which I added. Any advice or guidance would be greatly appreciated!

There’s two errors. One of which is causing the compiler, and the other of which is just causing broken behavior. You have to assign the output of Mathf.Clamp() to something. inAirVelocity is passed by value so the function does not change the original value.

Then there is the compiler error. The error says that the arguments (everything inside the parentheses) don’t match up with the existing definitions of clamp. When you call a function, Unity looks through all known definitions to see if the objects you passed as parameters line up with any of the definitions. Since they didn’t, the compiler threw an error. In your case, you tried to pass a Vector3, an int and a float.

Here is the definition that you want.

static float Clamp(float value, float min, float max);

So here’s what you actually want to do.

inAirVelocity = inAirVelocity.normalized * Mathf.Clamp ( inAirVelocity.magnitude , 0 , walkSpeed);
                               // or     * Mathf.Min( inAirVelocity.magnitude , walkSpeed) since magnitude > 0

Yeah. Oddly, I’ve had the same error with HTML/CSS, as well as renaming files in Windows. For example, if you have a file named “Photos of me” in Windows, and attempt to change the name to “Photos of Me”, when you hit enter, the file will “update” but its name will still be “Photos of me”. The workaround is to rename is to something completely different, and then re-rename it to the old name, but with proper capitalization.

I tried doing that in the unity script, changing “Mathf.Clamp” to “Mathf.somethingridiculous”, and then back to Mathf.Clamp, but no luck. Restarting Unity seemed to fix it. Sometimes Windows handles character changes between upper/lowercase in a weird way, I guess.