hi, being a beginner i am unable the tackle simple programming problem, and i am wondering if anyone could help me with this.
i have made a script that makes camera rotate around object similiar to the unity3d gizmo in the top-right corner. it works fine but i guess there is a better way of doing it. here is the code:
function RightRotate(ToRotation : float){
var t=0.0;
while (t < 1.0) {
t += Time.deltaTime * (1.0/0.2);
x=Mathf.Lerp(x,ToRotation,t);
y=Mathf.Lerp(y,0,t);
yield;
}
}
x and y represents rotations by x and y axis. this function takes the end point of the rotation. that could be 0,90,180 and 270. i am also converting 360 to 0 and so on…
i am using this function like this:
if(xRotValue<270 xRotValue>=180){
cam.LeftRotate(270);
}
if(xRotValue<180 xRotValue>=90){
cam.LeftRotate(180);
}
for all values and combinations that i can think of…so that is bad. it works though. can it be done in a simplier way. for example to try to calculate the degrees to rotate the camera by the nearest point (0,90,180 270 or 360). how to calculate that??
i guess this is simple to people who know to program well…thanks!