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 TommiH · Jul 26, 2012 at 04:14 PM · rotationquaternionaxiseuler angles

Duplicating rotation with axis constraints

Hello.

I need to have one object duplicate the rotation of another, with the following complications:

There is Object A, which may be rotated through various, arbitrary methods, such as animation, physics, etc. There is also Object B, which must imitate Object A's rotation.

If it was that simple, I could just take Object A's rotation change and rotate Object B with it. However, Object B may have axis-based limitations: it may, for example, only rotate around the X and Y axes, and only rotate at half a speed around Y. (The axes themselves are constant, for example world axes, or axes of an unmoving parent, so when it comes to these limitations, the axes won't rotate with the objects.)

The problem is that I can't break a Quaternion into axis aligned components in order to apply the limitations. I've also tried Euler Angles, but the way Unity breaks the Quaternion into Euler Angles seems arbitrary, so just setting eulerAngles.z = 0 will mess things up.

Intuitively, this seems like a simple thing to do, but I can't figure it out. Can anyone help?

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

1 Reply

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

Answer by ScroodgeM · Jul 27, 2012 at 03:42 PM

eulers are not so bad 8) tell us if something bad in this script

Rotater.cs

using UnityEngine;
public class Rotater : MonoBehaviour
{
    public Vector3 Limits = Vector3.one * 50f;
    public Vector3 Speeds = Vector3.one * 10f;
    public Transform targetRotation;
    Vector3 myRotation = Vector3.zero;
    void Update()
    {
        Vector3 targetEuler = targetRotation.rotation.eulerAngles;
        for (int i = 0; i <= 2; i++)
        {
            myRotation[i] = Mathf.Clamp(Mathf.MoveTowards(myRotation[i], Mathf.Repeat(targetEuler[i] + 180f, 360f) - 180f, Time.deltaTime * Speeds[i]), -Limits[i], Limits[i]);
        }
        transform.rotation = Quaternion.Euler(myRotation);
    }
}
Comment
Add comment · Show 1 · 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 TommiH · Jul 30, 2012 at 12:10 PM 0
Share

Thanks! I think this is exactly what I need. (The limits and speeds work a bit differently but I can figure them out.)

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

Rotating on a plane 2 Answers

Rotating multiple points in space. 0 Answers

How to get object's X axis rotation EXACTLY as in inspector ? 2 Answers

[Please!] Noob need's help with planet gravity movement. 2 Answers

how can i substract one axis by 180? 2 Answers


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