- Home /
transform.rotate only 1 time for 180 degrees?
Can somebody give a link or help me! How to make transform.rotate for only 1 time in .Js ? So it will be only one rotation, instead of endless moving or GetKey() moving!
I would be grateful for any kind of help!
Yes, but how to make it smooth-slowly? not instant (for helicopter rotation)?
Again, i am not sure if this answers your question, so i will convert this to an answer if it give you what you need. please, vic19993 tell me so i don't look like an idiot with an answer as a comment.
hrm. i can't tell what you're asking. I couldn't be more confused
transfrorm.Rotate(0,180,0);
that will make it rotate once, just put it in a start function or an if statement or whatever, then you can rotate the object.
but i assume you know that. i think you have knowledge of transform.Rotate already because you asked about it. that's what's bugging me. I don't think that that was what you were looking for, and your question isn't very clear.
i think that maybe you want a way to only run this once if it's not running once and you can't make it, (no offense) you may want to look up other things in unity before transform.Rotate; because it is very basic in most coding languages (i think) and you need an understanding of it before you will be able to really do things in unity.
things like this
function Update (){
transform.Rotate(0,180,0);//runs constantly
if(Input.Get$$anonymous$$ey("w")){
transform.Rotate(0,180,0);//runs while w is held
}
}
function OnTriggerStay (){
transform.Rotate(0,180,0); //runs while triggered
}
function OnCollisionStay (){
transform.Rotate(0,180,0); //runs while collided
}
will run constantly.
things like this
function Update (){
if(Input.Get$$anonymous$$eyDown("w")){
transform.Rotate(0,180,0);//runs once when w is pushed
}
}
function OnTriggerEnter (){
transform.Rotate(0,180,0); //runs once when triggered
}
function OnCollisionEnter (){
transform.Rotate(0,180,0); //runs once when collided
}
function OnTriggerExit (){
transform.Rotate(0,180,0); //runs once when exited
}
function OnCollisionExit (){
transform.Rotate(0,180,0); //runs once when exited
}
run only once. there are hundreds of sets like this in unity, not to mention in just JS in general (while loops, for loops. run constantly for a while, just plain code and ifs outside loops run onces, etc).
we can't give you all the ways to make it run once, there are hundreds of ways. you have to find the best method to run you code for your situation, and because you didn't mention it, we can't even tell you which one to use this time. the only thing that stays the same is
transfrorm.Rotate(0,180,0);
so that is all the answer i can truly give.
Answer by akguldeniz · May 01, 2014 at 09:03 PM
you can use GetKeyUp or GetKeyDown. and if you want this just one time you can create a boolean variable for example var turn = true;
if(Input.GetKeyDown.("w") && turn == true){ //rotate script here turn false; }
Yes, but how to make it smooth-slowly? not instant (for helicopter rotation)?
this was not answered in this question. do you still need it? because it can be done with a simple for loop
for (var i = 0; i < timetodothisloop; i++){
transform.Rotate(0,180/timetodothisloop,0);
}
pleas note, no offense to the guy who answered this one, Vic added that last part later, so he answered it the best anyone could at that time
Your answer
Follow this Question
Related Questions
rotation script in unity 3 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Why am I getting 2 different results with RotateAround? Trying to move cubes on surface of sphere. 0 Answers
Object reference not set to an instance of an object 1 Answer