- Home /
Set fixed rotation position of object in world space but only x axis
So far I have this transform.eulerAngles = new Vector3(50,0,0);
and its all good, but i am changeing x and y trough other scripts, is there a way to change only x axis, so they dont conflict?
Answer by JxWolfe · Jun 18, 2017 at 07:16 PM
do you use physics? Because the Rigidbody has a fixed rotation... or every update you can have:
void Update()
{
transform.rotation = new Quaternion (startingRotationX, transform.rotation.y, transform.rotation.z, transform.rotation.w);
}
with:
float startingRotationX;
void Start()
{
startingRotationX = transform.rotation.x;
}
That would set your rotation x to your starting rotation every update
Thank you so much for your reply, but this did the job :) transform.eulerAngles = new Vector3(50,transform.eulerAngles.y,transform.eulerAngles.z);
Answer by Lukassds223 · Jun 20, 2017 at 01:03 AM
SOLUTION: transform.eulerAngles = new Vector3(50,transform.eulerAngles.y,transform.eulerAngles.z);
that would also do it, just using the eulerAngles ins$$anonymous$$d of transform.rotation