- Home /
Question by
Kissanaattori · Feb 11, 2014 at 02:57 PM ·
cameravariable
Limiting a distance variable
What function should I use, I want to limit the distance of my camera to the player so it doesn't go too far or doesn't get too close. My distance variable is distance, and it's default setting is 7.0. Then there's DistanceMin, and it's default setting is 7.0 aswell. Finally there's DistanceMax, which is defautly 30.0. Distance is the variable, changing here, I want the script to check if`(distance)= DistanceMin {distance = DistanceMin}` Same should be applied on DistanceMax. Thanks in advance.
Comment
Best Answer
Wiki
Answer by magnussolidus · Feb 11, 2014 at 03:18 PM
this is quite simple, here is some JavaScript sample. All you need to do is check if the actual distance value is between the min and max range.
public var distance : float;
public var distanceMin : float = 7.0;
public var distanceMax : float = 30.0;
function Update() {
if(distance < distanceMin) {
distance = distanceMin;
}
else if(distance > distanceMax) {
distance = distanceMax;
}
else {
// distance have an acceptable range
}
}