I would like to rotate an object based on the rotation of it’s parent, but I would like to keep it’s translation constant (frozen) so I can target another camera on it and thus creating a sort of compass. How can I sample only the rotation info and pass it onto my object? This must be simple, but has me completely flummoxed.
Does the object have to be set to the other objects child? as it seems you’re trying to override something fundamental about the parent/child relationship?
Perhaps just copying the other objects rotation will suffice without having to make one the child of the other?
If you need to do it this code works:
public class DontYouDareMove : MonoBehaviour {
private Vector3 loc;
void Start () {
loc = transform.position;
}
void Update () {
transform.position = loc;
}
}
Thank you for your reply. However the object still moves because as far as I can see it is rotating around the parent’s pivot point.
It doesn’t have to be the child, only inherit the same rotation values so it can act as a 3d compass.
BTW The rotation of the “parent” comes from two sliders that I have set up, but when I try for the “compass” to be affected by the same sliders it overrides the rotation of the terrain.
It seems to me that the simplest solution would be to attach the slider script to the “compass” but so far no luck. Below is the slider code, how do I make it affect multiple objects (without parenting)?
I seem to have sorted this problem out, but it’s probably not very elegant. If someone can help me tidy up the code, it would be great.
I have attached the code to an empty game object and then the sliders rotate both the compass and the object called “maastricht”. I can add other objects to the list, but there must be a nicer way of doing this.
Thanks
var slider : float;
var slider2 : float;
function OnGUI () {
if (Input.GetMouseButtonUp(0)) {
slider = 0.0;
slider2 = 0.0;
}
slider = GUI.HorizontalSlider( Rect(550,20,300,30), slider, -0.1, 0.1);
var go = GameObject.Find("maastrstructmap");
var co = GameObject.Find("compass");
go.transform.Rotate(Vector3.up * slider);
co.transform.Rotate(Vector3.up * slider);
slider2 = GUI.VerticalSlider( Rect(860,20,30,300), slider2, -0.1, 0.1);
var be = GameObject.Find("maastrstructmap");
var on = GameObject.Find("compass");
be.transform.Rotate(Vector3.right * slider2);
on.transform.Rotate(Vector3.right * slider2);
}
Although I have achieved the desired effect with the sliders, I am still wondering how to transfer the rotation information from one object to another. I have a compass which I can rotate and would like a gameobject to rotate with it around it’s own local axis, not the worlds or the compasses. Can I attach some code to the gameobject which copies the rotation info from the compass?