- Home /

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

**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); } }

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

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Get local euler angles by Quaternion 1 Answer

Lookat via Single Axis 0 Answers

how can i substract one axis by 180? 2 Answers

Rotating multiple points in space. 0 Answers

Rotate object on one axis with slerp 1 Answer