• 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 ardizzle · Jan 11, 2014 at 01:13 PM · rotationjavascript

Odd rotation on a pipe

I have a script that lets there player spawn, rotate, and place pipe. We have 3 different pipes that we play with, Straight, T-Joint, and Corner. The first 2 work great but the 3rd one keeps rotating on the wrong axis no matter what axis I try to rotate. If I rotate through the inspector it rotates how I want it to though. So whats going on?

 if(Input.GetButtonDown("Rotation") && buildingThree.rotateEnabled == true)
              {
                  structure.transform.Rotate(0,Input.GetAxisRaw("Rotation") * 45,0);
              }
Comment
Add comment · Show 4
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 ardizzle · Jan 14, 2014 at 10:38 PM 0
Share

Still having trouble with this. Can't seem to make any progress

avatar image HappyMoo · Jan 14, 2014 at 10:53 PM 0
Share

What did you try? How is the rotation wrong?

avatar image Nanobrain · Jan 14, 2014 at 10:53 PM 0
Share

Are you trying to rotate it on the local or world axis?

avatar image ardizzle · Jan 14, 2014 at 11:15 PM 0
Share

ins$$anonymous$$d of the pipe laying sideways with both opens parallel to the ground on is parallel and the other is straight up. I didn't define local or world because every other pipe and object rotates fine.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HappyMoo · Jan 15, 2014 at 02:04 AM

Not sure what you're doing - it works for me...

Pipes

Create a new Scene and drop this on the Main Camera:

 using UnityEngine;
 using System.Collections;
 
 public class PipeRotation : MonoBehaviour {
 
     GameObject[] pipes = new GameObject[3];
     GameObject selector;
     int sel = 1;
     bool animating = false;
     void Start () {
         Camera.main.gameObject.AddComponent<Light>().range = 30;
         pipes[0] = Cyl(0,-3.5f,0, 0,0,0, 3,0.1f,3);
         pipes[1] = Cyl(0,-3.5f,0, 0,0,0, 3,0.1f,3);
         pipes[2] = Cyl(0,-3.5f,0, 0,0,0, 3,0.1f,3);
         Cyl(0,-3,0, 90,0,0, 1,1.5f,1).transform.parent = pipes[0].transform;
 
         Cyl(0,-3,0, 90,90,0, 1,1.5f,1).transform.parent = pipes[1].transform;
         Cyl(0,-3,-0.75f, 90,0,0, 1,0.75f,1).transform.parent = pipes[1].transform;
 
         Cyl(0.75f,-3,0, 90,90,0, 1,0.75f,1).transform.parent = pipes[2].transform;
         Cyl(0,-3,-0.75f, 90,0,0, 1,0.75f,1).transform.parent = pipes[2].transform;
         Cyl(0,-3,0, 0,0,0, 1,0.5f,1).transform.parent = pipes[2].transform;
         
         pipes[0].transform.position += Vector3.left*4;
         pipes[2].transform.position += Vector3.right*4;
 
         selector = Cyl(0,-3.5f,0, 0,0,0, 3.5f,0.05f,3.5f);
     }
 
     GameObject Cyl(float x, float y, float z,
                    float rx, float ry, float rz,
                    float sx, float sy, float sz) {
         GameObject o = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
         o.transform.position = new Vector3(x, y, z);
         o.transform.rotation = Quaternion.Euler(rx, ry, rz);
         o.transform.localScale = new Vector3(sx, sy, sz);
         return o;
     }
     
     void Update () {
         float osc = 0.5f * Mathf.Sin(10*Time.time);
         selector.transform.localScale = new Vector3(3.5f+osc,0.05f,3.5f+osc);
         if (!animating)
         {
             float horiz = Input.GetAxisRaw("Horizontal");
             if (Mathf.Abs(horiz)>0.5f)
             {
                 sel = (sel + 3 + (int)Mathf.Sign(horiz)) % 3;
                 StartCoroutine(MoveSelector());
             }
             float vert = Input.GetAxisRaw("Vertical");
             if (Mathf.Abs(vert)>0.5f)
             {
                 StartCoroutine(RotatePipe(Mathf.Sign(vert)));
             }
         }
     }
 
     IEnumerator MoveSelector() {
         animating = true;
         Vector3 target = new Vector3(sel*4-4,-3.5f,0);
         while(selector.transform.position != target)
         {
             selector.transform.position = Vector3.MoveTowards(selector.transform.position, target, 0.3f);
             yield return null;
         }
         animating = false;
     }
 
     IEnumerator RotatePipe(float direction) {
         animating = true;
         GameObject pipe = pipes[sel];
         Quaternion target = pipe.transform.rotation * Quaternion.Euler(0,direction*90,0);
         while(pipe.transform.rotation != target)
         {
             pipe.transform.rotation = Quaternion.RotateTowards(pipe.transform.rotation, target, 3f);
             yield return null;
         }
         animating = false;
     }
     
 }

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 HappyMoo · Jan 21, 2014 at 01:13 AM 0
Share

Did that help?

avatar image ardizzle · Jan 21, 2014 at 04:21 AM 0
Share

Sorry I got busy and forgot about the question. Thanks for trying to help but my friend figured out a round about way today. We made the object into a child of an empty game object and rotated the parent. It worked.

avatar image HappyMoo · Jan 21, 2014 at 04:34 AM 0
Share

Yes, that's what I was doing in my code above 6 days ago

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Smooth Rotation Help 1 Answer

Determining Look Rotation As > A Number? 1 Answer

Rotating Sprite 2D with JAVASCRIPT coding. 2 Answers

How to change the pivot point of a mesh in script? 1 Answer

How do I rotate planes around a cube? 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