- Home /
Constrain XZ while setting local Y-rotation free. How?
Hi there,
I have a game object that should be contraint to another game object's rotation. But I want this game object to able to freely rotate around it's own Y axis. (Because I want to rotate this game object via rigidbody.AddRelativeTorque later).
I tried around with transform.localEulerAngles and transform.eulerAngles e.g:
transform.localEulerAngles = new Vector3(planetaryOrientation.localEulerAngles.x, transform.localEulerAngles , planetaryOrientation.localEulerAngles.z);
But all attempts couldn't manage to do what I need. The "free" axis is never the local Y axis of the game object, but seams to be the Y axis in world space.
Is there maybe an other way to set a special local axis free while the other axis are constrait to another game object??
Could you describe the situation some more? $$anonymous$$nowing what you are after would allow to give a more appropriate answer.
Here I could tell you to apply the rotation of the top object to the sub object and then apply a rotation to the sub object on the axis by the amount needed, but they could be better ways.
Okay, I'm working on a game that is arranged in a planetary gravity setup. The player is attached to a game object that is always orientated parallel to the planets surface. But I need the player to be able to move freely around it's own Y axis while it is attached to the other gameobject, because I want to rotate it by using rigidbody.AddRelativeTorque. The player is a rigidbody of course.
So you want only the player to be constrained on the x and z axis if i'm understanding this correctly. Have you tried setting the players rigidbody "freeze rotation" constraints to stop rotation on these two axes?
Hey - thank you but this is not what I need. Sorry for my english.
Answer by Kiwasi · Jun 09, 2014 at 07:38 PM
Hinge Joints do exactly that
I'm not sure if that might be compatible with my setup, but I'll give it a try and tell you later if this is the solution. THX!
Hinge Joints seams to be a solution, but in my case it isn't. The joint needs a connected body with a rigidbody, but my other game object hasn't a rb and even if I try to give it one, the rotation is not how it should be.