- Home /
"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:
else
{// 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!
the argument u used is not in proper manner it required (float/int,float/int,float/int) but u using (vector3,int,float)
Hi Yogee, thanks for the advice. That makes sense. How would I go about clamping just the X and Z components of a vector3? I don't need to clamp the Y at all, so that may be the issue.
Answer by Peter G · Nov 11, 2013 at 04:30 AM
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
Peter G,
Thanks so much for answering my question so quickly, and for explaining the reasoning behind the error! Please excuse my lack of understanding, but I'm not able to get it working.
$$anonymous$$y code is as follows:
if (is$$anonymous$$oving) inAirVelocity += targetDirection.normalized Time.deltaTime inAirControlAcceleration;
inAirVelocity = inAirVelocity.normalized * $$anonymous$$athf.Clamp( inAirVelocity.magnitude, 0, walkSpeed );
Which no longer presents an error. However, when I start the game, I'm presented with the error below, and I'm no longer able to control the acceleration of my character in-air.
$$anonymous$$issing$$anonymous$$ethodException: UnityEngine.$$anonymous$$athf.clamp Boo.Lang.Runtime.DynamicDispatching.$$anonymous$$ethodDispatcherFactory.ProduceExtensionDispatcher () Boo.Lang.Runtime.DynamicDispatching.$$anonymous$$ethodDispatcherFactory.Create () Boo.Lang.Runtime.RuntimeServices.DoCreate$$anonymous$$ethodDispatcher
Ok, this is weird.
When I look up the above error on Google, it seems that it's usually due to improper capitalization. If that's the case for me, the error is telling me "$$anonymous$$athf.clamp" is bad, because the actual syntax is "$$anonymous$$athf.Clamp" with a capital C... however, the line it's referring to in the script DOES have a capital C.
Please tell me I'm not going crazy haha
Restarted Unity, which seemed to help it realize that that uppercase C was in fact uppercase.
Thanks everyone for the help!!!
Answer by BrendanFarrell · Nov 11, 2013 at 06:39 AM
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.
Your answer
Follow this Question
Related Questions
How do i make jumps follow through with rigidbody2D.addforce? 1 Answer
Jumping while moving 1 Answer
Spaceship Control Help 2 Answers
How do I script Street Fighter style movement? 1 Answer
Why when i press space button nothing was happened 0 Answers