armory3d / armory

3D Engine with Blender Integration
https://armory3d.org
zlib License
3.07k stars 315 forks source link

Parent rotation inheritance #1008

Open Gedankenexper1ment opened 5 years ago

Gedankenexper1ment commented 5 years ago

If I use get rotation on a parented object that has been rotated by it's parent, the values returned are local, (i.e. 0,0,0)

This can cause problems, especially with nodes like 'look at' that control rotation, because the results are applied locally. Therefore the object may initially 'look at' the specified location, but when rotated by a parent object the 'look at node' does not update the rotation (even if activated each frame with On Update).

This could be solved by implementing vertex parenting (where the child inherits only location and not rotation), or even better, implementing an interface that allows control over what is inherited by parents: maybe a series of six check boxes for what to include or exclude from the parent relationship (loc x y z and rot x y z).

For attached blend, use space to print child rotation: test.zip

zicklag commented 5 years ago

Yeah, I have had quite a bit of trouble just figuring out how to set rotation in world space for 'look at' solutions and others. I know there is a way to do the math, but I was never quite able to set an object's global rotation if it had a parent:

Didiercode commented 5 years ago

@zicklag Your difficulties could come from thoses simple tips to well remember when doing rotation with parenting and I maybe it could help you: tip 1 : if an object has a parent, it's position/rotation/scaling are mesured in the local coordinate system of the parent, as if it was a vertex of the parent. tip2 : the position of the child's center is measured from the parent's center inspite of it's origin in the global coordinate system tip3 : the expression q p q^-1 rotate all quaternion vector p

zicklag commented 5 years ago

Thanks again for the tips @Didiercode. I'll probably take another hack at this sometime. :smiley: