Hi Folks, I needed to do a box rotate around a pivot, I know its trivial and there are other posts about it but I did a little script that does the job, I hope it can help someone else out there, that's it. http://www.youtube.com/watch?v=Z9O0u0EmtiI&feature=youtu.be Code (csharp): /* _____ _ ______ _ | __ \ | | | ___ \ | | | | \/ ___ _ __ ___ _ __ __ _| | | |_/ / __ _ _______ ___ | | ____ _ | | __ / _ \ '_ \ / _ \ '__/ _` | | | ___ \/ _` |_ / _ \ / _ \| |/ / _` | | |_\ \ __/ | | | __/ | | (_| | | | |_/ / (_| |/ / (_) | (_) | < (_| | \____/\___|_| |_|\___|_| \__,_|_| \____/ \__,_/___\___/ \___/|_|\_\__,_| ==***== * In a lazy sunday day. */ using UnityEngine; using System.Collections; public class RotateAroundPivot : MonoBehaviour { public Vector3 Pivot; public bool DebugInfo = true; //it could be a Vector3 but its more user friendly public bool RotateX = false; public bool RotateY = true; public bool RotateZ = false; void FixedUpdate() { transform.position += (transform.rotation*Pivot); if (RotateX) transform.rotation *= Quaternion.AngleAxis(45*Time.deltaTime, Vector3.right); if (RotateY) transform.rotation *= Quaternion.AngleAxis(45*Time.deltaTime, Vector3.up); if (RotateZ) transform.rotation *= Quaternion.AngleAxis(45*Time.deltaTime, Vector3.forward); transform.position -= (transform.rotation*Pivot); if (DebugInfo) { Debug.DrawRay(transform.position,transform.rotation*Vector3.up,Color.black); Debug.DrawRay(transform.position,transform.rotation*Vector3.right,Color.black); Debug.DrawRay(transform.position,transform.rotation*Vector3.forward,Color.black); Debug.DrawRay(transform.position+(transform.rotation*Pivot),transform.rotation*Vector3.up,Color.green); Debug.DrawRay(transform.position+(transform.rotation*Pivot),transform.rotation*Vector3.right,Color.red); Debug.DrawRay(transform.position+(transform.rotation*Pivot),transform.rotation*Vector3.forward,Color.blue); } } }
thanks, just what i needed! but how do u save it, i need to do it in like editor so that the object gets the change
Why not just use Transform.RotateAround(); ?? http://answers.unity3d.com/questions/62059/rotate-around-a-point.html