- Home /
script for object to rotate around and come back
Hello , I need to write a script that have distance variable and speed variable the distance for the rotation degree and the speed for the speed of rotating & I want to when I Press H button for example my object rotate around z axis and come back to his first position but I write many codes and finally write this code but I can't find any success. Before this code I use animation but in my case animation isn't useful.
function Action_Pass_4(){
if(PassStage == false){
transform.Rotate(0,0,PassSpeed*Time.deltaTime);
}
if(Quaternion.Angle(transform.rotation,SecoundRotation)< 1){
PassStage = true;
}
if(PassStage == true){
transform.Rotate(0,0,-PassSpeed*Time.deltaTime);
if(Quaternion.Angle(transform.rotation,FirstRotation)< 1){
Pass_4 = false;
PassStage = false;
}
}
}
Let me see if I understand correctly - You want the game object to constantly revolve around some point in space (like a planet around a sun), and when the user presses H you want it to go back to the original position?
Do you want it to go straight there or do you want it to move there gradually (like animating movement)?
Answer by Oribow · Jul 03, 2013 at 07:37 PM
I know another way, that might work for you.
create a game object in the center of rotation
make your object child of this game object
rotate the game object and you will see, that your child object moves around the game object
Finally You can easily get the needed values.
The rotation can be modified via the game object.
my problem isn't that ; I want to rotate it with code for a degree and come back.
you can use your Script on the Parent Object i think this willworks
I use it but don't work properly ; I need to new way of scripting for this problem.