Hi, I have a problem with the transform.rotation. I want one object to repeat an other object’s rotations, but not completely, I need the rotation on the y Axis to be modified.
This is what I have right now
So, this code works great right now, I need to modify it in some way as to apply each axis rotation individually, what I would like it to look like is something like this
Another way is to store the current Rotation value and modify as needed and then finally reapply at the end of the method i.e.
Quaternion curRotation = this.transform.rotation;
// Order is important!! A rotation that rotates euler.z degrees around the z axis, euler.x degrees around the x axis, and euler.y degrees around the y axis (in that order).
curRotation.eulearAngles.z += rotz;
curRotation.eulearAngles.x += rotx;
curRotation.eulearAngles.y += roty;
this.transform.rotation = curRotation;
In your case though it can be simplified to basically:
using UnityEngine;
using System.Collections;
public class RotateScript : MonoBehaviour
{
public Transform otherTrans;
void Start()
{
if(otherTrans == null)
{
enabled = false;
return;
}
}
void Update()
{
float rotx = otherTrans.rotation.eulerAngles.x;
float roty = otherTrans.rotation.eulerAngles.y;
float rotz = otherTrans.rotation.eulerAngles.z;
//print(rotx + " " + roty + " " + rotz);
// Tweak roty in some way -- i.e.
roty = 0.0f;
//Then apply the new values
this.transform.rotation = Quaternion.Euler(rotx, roty, rotz);
}
}