Hi, here is a small function that I wrote to snap values. I was looking for a code or an engine function to do this, but I did not find one, so I attempted to write it myself.
I am sure it could be optimized, as I am not the best programmer.
It could be used to snap a camera to every 45 degrees, or a grid position to every 8 quants, ect.
63 factored by 45 returns 45, -487 factored by 45 returns -495 ect..
Hope someone finds it useful, and that it doesn't suck
function snap(value,snapv)
{
var temp;
var temp2;
if(snapv <= 0.2 && snapv >= -0.2)
{return(0);} //exit on zero, no dividing by zero!
temp = integer(abs(value)/snapv);
temp = temp*snapv;
temp2 = temp; //set
temp = integer(abs(value)-temp);
if (temp < abs(snapv)*.51)
{
return(integer(temp2*sign(value)));
}
temp2 = temp2+abs(snapv);
return(integer(temp2*sign(value)));
}