Unity 5 - How to addtorque to rigidbody without overriding axis constraints?
So, I'm kinda new to unity and coding and whatever so yeah. Anyway, I'm trying to make a rigidbody rotate with AddTorque, but only on the x axis. So I've got something like this:
void Movement(float moveRotationX,){
Vector3 rotation = new Vector3 (moveRotationX, 0.0f, 0.0f);
rb.AddRelativeTorque (rotation * rotationSpeed * Time.deltaTime,ForceMode.Acceleration);
}
So, this rigidbody I'm trying to rotate is also a child of another rigidbody, and I want it to follow its parent's y and z axis. So basically, its local rotation for these axis should both be 0. But, for some reason, it doesn't stay at 0. I think it's because, for this to happen, its y and z axis should be constrained/frozen, but the AddTorque overrides this when I try to do so in the inspector.
Idk I'm reaally just guessing here. Anyway, if someone knows a way to fix this, please tell!
Thank you for your attention.
Your answer
Follow this Question
Related Questions
Unity Bug? Parent object rotates around child object. 1 Answer
Referencing the rotation of a child? 0 Answers
Changing parent at runtime rotates object. 0 Answers
2D Rigidboy, have child keep upright but allow parent to rotate 1 Answer
How could I make the children of an object face the direction it is moving on the y-axis? 0 Answers