- Home /
Variable Mathf.Clamp not working... (SOLVED)
Hello, what i'm trying to do is clamp a variable between: '277.2847' and '-29.09483'
my code is:
var clampvar = 5f;
function Update () {
Mathf.Clamp (clampvar,-29.09483,277.2847);
Debug.Log(clampvar);
clampvar += 50;
}
Thank you sooo much if you can tell me why this isn't working :D
@Deeweext you should really convert that to an answer :)
Thanks it worked! :D convert to answer so i can set it as solved :D
Answer by Deeweext · Jul 07, 2013 at 02:24 AM
You are not storing the clamped value, you are telling it, hey what is the clamped version of this, fine, nevermind just wanted to know. You need to store it somewhere, or overwrite the original value like this:
var clampvar : float = 5.0;
function Awake ()
{
Debug.Log("Original value: " + clampvar);
clampvar = Mathf.Clamp(clampvar, -29.09483, 277.2847);
Debug.Log("Clamped value: " + clampvar);
clampvar += 50;
Debug.Log("Adjusted value: " + clampvar);
}
Your answer
Follow this Question
Related Questions
Clamp Mouse Zoom using Scroll Wheel (SOLVED) 2 Answers
How come my car-objects hood doesn't cast any shadows? 1 Answer
I have a problem with variables/networking. 0 Answers
Clamps not working! :( 0 Answers
MathF clamp not working 1 Answer