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 alone1992 · Jul 03, 2013 at 05:42 PM · rotate

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;
                                                               }
                      }
 
 
 }
 
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 Tomer-Barkan · Nov 26, 2013 at 06:38 AM 0
Share

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

1 Reply

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

Answer by Oribow · Jul 03, 2013 at 07:37 PM

I know another way, that might work for you.

  1. create a game object in the center of rotation

  2. make your object child of this game object

  3. 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.

Comment
Add comment · Show 3 · 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 alone1992 · Jul 04, 2013 at 06:02 AM 0
Share

my problem isn't that ; I want to rotate it with code for a degree and come back.

avatar image Oribow · Jul 04, 2013 at 08:38 AM 0
Share

you can use your Script on the Parent Object i think this willworks

avatar image alone1992 · Jul 04, 2013 at 09:32 AM 0
Share

I use it but don't work properly ; I need to new way of scripting for this problem.

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

17 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

Related Questions

object rotating around parent 1 Answer

expressions in statements must only be executed for their side effects 1 Answer

i need some code suggestions 1 Answer

Why isn't this script working? (Beginner in coding) 2 Answers

BeginScrollView question on auto increasing 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