- Home /
Question by
sarathraja_91 · Mar 04, 2021 at 10:08 AM ·
rotate object
one gameobject postion to another gameobject rotation
I have two objects in my scene, If I move one Gameobject in Y-axis the other object should rotate on the x-axis.
Actually now it is rotating but this is not that I was excepting, if gameobject 1 reaches red line the gameobject 2 should rotate on the x-axis to 90 degree.
This is code I'm using:
var target = GameObject.Find("Roof");
Vector3 newRotation = new Vector3(0, target.transform.position.y*23.5f, 0);
this.transform.rotation = Quaternion.Euler(newRotation.y, 0, 0);
rot.png
(34.6 kB)
Comment
first.. please make target as class variable and move target = GameObject.Find("Roof");
away from Update method to Start method.. (you are now doing a very taxing process every frame)
second: your object2 angle around x.axis follows object1 y postion with 23,5 ratio. So angle is 90 degrees when the y coordinate of object1 is 3.83. So is this the value when object1 hits the red line?