Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ShadowNukePie · Aug 22, 2016 at 05:08 AM · rotationloops

How to make an object do a multiple tasks forever

I want to make an object rotate left (either a certain amount of degrees/for a certain amount of time, whichever is easier) then rotate right for time/degrees and have that repeat forever. How would I go about doing this?

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 _Yash_ · Aug 22, 2016 at 08:37 AM 1
Share

use AnimationCurve: create animationcurve to rotate in either direction and then set Wrap$$anonymous$$ode to ping-pong.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by OsmiousH · Aug 22, 2016 at 11:46 AM

Use My script

NOTE: Remember to fill in the required values in the inspector

There are clear tooltips that describes what you have to Add

 //JS Javascript
 
 #pragma strict
     
     public enum AxisE{
         x,
         y,
         z
     }
     public enum RotationE{
         Right,
         Left
     } 
     @Header("INPUT-REQUIRED")
     @Tooltip("The axis the rotation should be in")
     public var Axis:AxisE;
     @Range(0,90)
     @Tooltip("The Speed the object should move in")
     public var RotationSpeed : float;
     @Tooltip("The Object that will rotaate")
     public var RotationObject : Transform;
     @Tooltip("Maximum Right value the Rotation Object can turn to in degrees")
     @Range(0,360)
     public var MaxRight : float;
     @Tooltip("Maximum Left value the Rotation Object can turn to in degrees")
     @Range(0,360)
     public var MaxLeft : float;
     @Header("SCRIPT DATA-DO NOT EDIT")
     public var CurrentRotation : Vector3;
     public var IsRotating : boolean;
     public var Rotation : RotationE;
     
     function FixedUpdate(){
         CheckSetRotations();
     }
     function CheckSetRotations(){
         CurrentRotation = RotationObject.eulerAngles;
         if(Axis == AxisE.z){
             RotateZ();
             if(CurrentRotation.z > MaxRight){
                 Rotation = RotationE.Left;
             }
             if(-CurrentRotation.z > MaxLeft){
                 Rotation = RotationE.Right;
             }
         }
         if(Axis == AxisE.y){
             RotateY();
             if(CurrentRotation.y > MaxRight){
                 Rotation = RotationE.Left;
             }
             if(-CurrentRotation.y > MaxLeft){
                 Rotation = RotationE.Right;
             }
         }
         if(Axis == AxisE.x){
             RotateX();
             if(CurrentRotation.x > MaxRight){
                 Rotation = RotationE.Left;
             }
             if(-CurrentRotation.x > MaxLeft){
                 Rotation = RotationE.Right;
             }
         }
     }
     function RotateZ(){
         IsRotating = true;
             if(Rotation == RotationE.Right){
                 RotationObject.Rotate(0,0,RotationSpeed);
             }
             if(Rotation == RotationE.Left){
                 RotationObject.Rotate(0,0,-RotationSpeed);
             }
         IsRotating = false;
     }
     function RotateY(){
         IsRotating = true;
             if(Rotation == RotationE.Right){
                 RotationObject.Rotate(0,RotationSpeed,0);
             }
             if(Rotation == RotationE.Left){
                 RotationObject.Rotate(0,-RotationSpeed,0);
             }
         IsRotating = false;
     }
     function RotateX(){
         IsRotating = true;
             if(Rotation == RotationE.Right){
                 RotationObject.Rotate(-RotationSpeed,0,0);
             }
             if(Rotation == RotationE.Left){
                 RotationObject.Rotate(-RotationSpeed,0,0);
             }
         IsRotating = false;
     }


@OsmiousH @Yash @ShadowNukePie

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 infinite360VR · Aug 22, 2016 at 11:58 AM 1
Share

OR, It is easy to create a simple animation using cool animation system

avatar image OsmiousH infinite360VR · Aug 27, 2016 at 10:54 AM 0
Share

Good point _

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

6 People are following this question.

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

Related Questions

Rotate while Boolean=true 0 Answers

Shower spiral cable simulation 1 Answer

Changing character X axis rotation so that gun points at target issue 0 Answers

URP Camera doesn't allow transparency? OBS Overlay 0 Answers

Enumerator in for loop acting strangely 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