- Home /
Copy rotation values in between objects.
I need to coppy the rotation values of an object to other objects ingame.
I wrote :
var target : Transform;
function Update () {
transform.rotation.x = target.transform.rotation.x;
transform.rotation.y = target.transform.rotation.y;
transform.rotation.z = target.transform.rotation.z;
}
But it doesn't work. The Rotations do update but they are not 1:1 the same and vary within a 40° range on all axis. This is way to much. How else could I do it? Parents don't Work since there are several objects depending on a single one, all with a big offset and transforming the parents rotation only causes the Objects to shift regarding their offset.
First of all, if you want to set the rotation of the target object, it needs to be on the left side of the equation. The second thing is: Does target.transform.rotation = transform.rotation;
do the trick?
No,, target is the Object the rotation is co$$anonymous$$g from. Yea I should have named it otherwise but this is only a part of the code.
Answer by Ricewind1 · Jun 12, 2014 at 01:55 AM
Vector3 newRotation = new Vector3(go2.transform.eulerAngles.x, go2.transform.eulerAngles.x, go2.transform.eulerAngles.z);
gameObject.transform.eulerAngles = newRotation;
Or the following (untested)
Vector3 newRotation = gameObject.transform.rotation.eulerAngles;
Took me ages to figure out what didn't work. Was in JS ins$$anonymous$$d of C# :P Fail. Also you had x twice. But thats fine :D In the end, this is what I was looking for. Thank you :D
void Update () {
var target = GameObject.Find("center");
Vector3 newRotation = new Vector3(target.transform.eulerAngles.x, target.transform.eulerAngles.y, target.transform.eulerAngles.z);
this.transform.eulerAngles = newRotation;
}
Your answer
Follow this Question
Related Questions
Save Timer HighScore 1 Answer
An instance of type (Script) is required to access non static member (Script) 1 Answer
JS file deleting multiple game objects 0 Answers
Breaking a loop, Javascript? 3 Answers
GuiTexture Width Change 1 Answer