- Home /
Finish rotation in the same angle of beginning?
Finish the rotation in the same angle of beginning?
Hi Everyone,
I'm trying to make one object that spins to finished his rotation in the same angle of start.
For example if start the spin in angle cero of 360 degree, I want to finished in the same angle.
I'm using a slider to control Speed, so I really need to change this script because depends of other script.
I did try with my function "rotatehome"
Please any advice is very appreciated
var Speed = 1.5;
var rotatehome = true;
function Update(){
amtToMove = guiNew. vSliderValue * Speed;
if(guiNew.showGo == 1){
rotatehome = false;
transform.Rotate(0,guiNew. vSliderValue * Speed,0);
}else{
if (rotatehome){
transform.Rotate (0,0,0);
}
}
Answer by iwaldrop · Feb 10, 2013 at 06:17 AM
Probably the best thing to do, if the rotation that you're starting from differs from time to time, is record the angle of rotation before you start. Then, when you're finished rotating, either set it directly or lerp to it.
If you're always going to be starting and ending at the same rotation, then just set it in the inspector. This way when the object is initialized in the scene you can ensure that the rotation is set correctly and then you can always finish it at the appropriate rotation as well.
Hi iwaldrop, I didn't understand very well.
I have to change my script and create a new variable and then set it in the inspector?
Thanks
I was simply saying that, depending on your situation, there are a couple of different ways to solve this problem. I'm describing two different cases, if that helps you. The first case is if you need to set your rotation back to something that is only known at run-time, while the second describes a case where you know what the rotation is going to be at design-time.