- Home /
how to make an objects rotation independent from its parents.
i want an object to move with its parent but not rotate. how would i do this?
idea 1: don't parent the object, keep the both separately move that object through code like sub.position= main.position+ distance between them idea 2: parent that object and write the code for both, for parent u writing +rotation means u should write the code for child also as -rotation (same value)
Answer by Kleptomaniac · Mar 11, 2013 at 05:27 AM
I solved this a while ago by using LateUpdate() ... not sure if it is exactly a legitimate solution but it seems to work fine:
function LateUpdate () {
if (transform.rotation != Quaternion.Euler(0, 0, 0)) {
transform.rotation = Quaternion.Euler(0, 0, 0);
}
}
Attach this to your child object. Again, there may be a way better way to do this, so don't hold this to me.
Hope that helps,
Klep
That won't work because i want the child object to still be able to rotate, not be locked at 0,0,0. Thank you for trying though.
$$anonymous$$alarkey
Answer by HPrigg · Oct 28, 2013 at 07:10 AM
Could you "pseudo parent" it? Have the child object call the parent object's movement commands, however you're doing that, be it AddForce or changing the velocity or what have you. Then the child object would mimic the movement of the parent without mimicking rotating. Unless you need it parented for other reasons.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Changing the parent transform of the First Person Controller 1 Answer
How to make a animation rotation js.script? 2 Answers
Is anyone able to fix my code? 3 Answers
How to rotate collider? 1 Answer