Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Vic19993 · May 01, 2014 at 07:23 PM · javascripttransformrotaterotatearound

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)?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rednax20 · May 01, 2014 at 07:47 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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; }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rednax20 · May 02, 2014 at 10:12 PM 0
Share

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);
 
 }
avatar image rednax20 · May 02, 2014 at 10:13 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges