- Home /
Implementing mathf ?
so far in my zoom script for my camera to zoom in and out iv got
public var fov = 60;
public var fovSpeed = 1;
function Update(){
if (Input.GetAxis("Mouse ScrollWheel")> 0){
Camera.main.fieldOfView = fovSpeed--;
}
if (Input.GetAxis("Mouse ScrollWheel")< 0){
Camera.main.fieldOfView = fov ++;
}
}
i want to add a clamp so i dont zoom in too far but how do i implement this?
Answer by dannyskim · Feb 08, 2012 at 09:17 PM
Simply put the Mathf.Clamp after the setting that you are altering.
Camera.main.fieldOfView = fov++;
Camera.main.fieldOfView = Mathf.Clamp( Camera.main.fieldOfView, min, max );
yea i did an the longer method without mathf this way:
public var fov = 60;
public var fovSpeed = 2;
public var fov$$anonymous$$in = 30;
public var fovmax = 70;
function Update(){
if (Input.GetAxis("$$anonymous$$ouse ScrollWheel")> 0){
Camera.main.fieldOfView = fov--;
}
if (Input.GetAxis("$$anonymous$$ouse ScrollWheel")< 0){
Camera.main.fieldOfView = fov ++;
}
if (fov > fovmax){
fov = fovmax;
}
if (fov < fov$$anonymous$$in){
fov = fov$$anonymous$$in;
}
} but thanks for the answer ill use that ins$$anonymous$$d :)
Your answer
Follow this Question
Related Questions
Performance of Mathf.Clamp vs if-else statement? 1 Answer
Change field of view over time 1 Answer
Mouse-Scroll Zoom 1 Answer
triangles angles 3 Answers
GUI texture ? help please 0 Answers