• 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
1
Question by Kossuranta · Aug 15, 2014 at 04:12 PM · rotationrotation axis

Rotation on only single axel while others staying still

Currently rotation is going like this:

Rotation going like this

I would it need to rotate only on X-axel while Y would stay 0 and Z would stay 90. I have tried transform.Rotate(Vector3.up spinSpeed Time.deltaTime) and transform.Rotate(0f, spinSpeed * Time.deltaTime, 0f), but both have same problem. Currently code isn't completed and at end it would find closes rotation from list and use it as targetRotation.

 using UnityEngine;
 using System.Collections;
 
 public class Slot : MonoBehaviour {
     public Vector3 eulerAngleVelocity;
     public float spinSpeed;
     float spinSpeedOrig;
     public float timer;
     public float currentRotation;
     public float targetRotation;
     public float goingRotation;
     public float timerTime;
     bool once;
     
     void Start()
     {
         spinSpeedOrig = spinSpeed;
         timer = Random.Range (30.5f, 50f);
     }
     
     void Update()
     {
         if(timer > 0)
             timer -= Time.deltaTime;
         else if(spinSpeed > 0)
             spinSpeed -= Time.deltaTime * 100;
         else if(!once)
         {
             once = true;
             spinSpeed = 0;
             currentRotation = transform.eulerAngles.x;
             print(currentRotation);
         }
         else
         {
             timerTime += Time.deltaTime * 0.1f;
             goingRotation = Mathf.Lerp(currentRotation, targetRotation, timerTime);
             transform.eulerAngles = new Vector3(goingRotation, 0, 90);
         }
 
         eulerAngleVelocity = new Vector3(0, spinSpeed, 0);
 
     }
     
     void FixedUpdate()
     {
         //transform.Rotate(Vector3.up * spinSpeed * Time.deltaTime);
 
         //transform.Rotate(0f, spinSpeed * Time.deltaTime, 0f);
 
         Quaternion deltaRotation = Quaternion.Euler(eulerAngleVelocity * Time.deltaTime);
         rigidbody.MoveRotation(rigidbody.rotation * deltaRotation);
     }
 }


Comment
Add comment · Show 2
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 radiKal07 · Aug 15, 2014 at 04:38 PM 0
Share
 Vector3 tmpRotation = new Vector3(spinSpeed * Time.deltaTime, 0.0f, 90.0f);
 transform.Rotate(tmpRotation);
avatar image Kossuranta · Aug 15, 2014 at 05:43 PM 0
Share

Well that would rotate 90 degrees on every update at Z-axel, so nope. That kinda tries to do same as what I have already tested: transform.Rotate(spinSpeed * Time.deltaTime, 0f, 0f);

1 Reply

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

Answer by robertbu · Aug 15, 2014 at 07:17 PM

The problem you outline is not fixable...directly. Unity uses Quaternions for rotations. Euler angles are derived from the Quaternion. For example, if you do:

  transform.eulerAngles = new Vector3(180.0f, 0.0f, 0.0f);
  Debug.Log(transform.eulerAngles);

The output is (0,180,180), which is the same physical rotation, but a different euler representation.

There a couple different ways to work around the issue. Assuming there is nothing else impacting the rotation of this object, I recommend treating eulerAngles as write-only. This means you will need to get rid of line 31, and instead get the rotation from an initialized value in Start. It also means if you do any kind of reset on this rotation, you will need to assign 'currentRotation' from either 'goingRotation' or 'targetRotation' depending on how and why you do the reset.

Comment
Add comment · 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

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

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

Why is a child object not rotating properly with parent? 1 Answer

Need help with sprite rotation 0 Answers

Rotating On Two Axes Independantly 0 Answers

How can I make player rotation control camera's x rotation and mouse control it's y rotation? 1 Answer

please help to rotate a cube around it's own axis 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