2D Rigidboy, have child keep upright but allow parent to rotate
The title says it all, trying to have my parent rotate but an object attached to it stay upright via the keep upright variable on 2d rigidbody, tried using hinge joints to no avail, is this possible?
Answer by Ascaria · Mar 16, 2017 at 08:47 AM
Hi,
first of all, you have 2 choices to set rotation: 1) transform.localRotation - this is relative to parent, so zero rotation means same as parent 2) transform.rotation - this is world rotation, so the angle you set is angle it will face regardless of parents
if child rigid body it is not necessary, you could try to create a script and attach it to your child
private Quaternion rotation;
private void Awake() {
rotation = transform.rotation;
}
private void LateUpdate() {
transform.rotation = rotation;
}
This way you are setting global rotation of child to one that was set right at the beginning, so object keeps facing that direction what you set in the editor.
If you look here https://docs.unity3d.com/uploads/Main/monobehaviour_flowchart.svg you see that in late update, you can set rotation after everything was applied so it is not changed by physics before render.
Your answer
Follow this Question
Related Questions
destroy other child objects when the parent counts more than 1 child 1 Answer
Unity Bug? Parent object rotates around child object. 1 Answer
¿Why wont child move with parent? 0 Answers
Referencing the rotation of a child? 0 Answers
Unity 5 - How to addtorque to rigidbody without overriding axis constraints? 0 Answers