Child changes geometry when i rotate the parent.
Parent is empty object and has scale (1, 1, 1).
Child is basic Capsule with adjusted rotation, position and scale.
I already tried deleting everything and i started over but nothing changed.
Please help me, thanks.
Related
I am working with Matrix4x4's in Unity and have some local space Matrices under parent Transforms that have their own rotation, scale and position. Whenever a parent Transform is moved, scaled or rotated I need to reflect it also on to the child Matrices.
For translating the position of the child into worldspace relative to the parent, that seems pretty easy:
WorldSpaceMatrix = LocalSpaceMatrix * transform.localToWorldMatrix;
However I am really struggling with how to reflect a change in parent rotation on to a child Matrix and also update position due to any position offset. The above gets the local rotation of the Matrix itself which is fine. But it doesn't update any change in position. Effectively I need to "RotateAround" the parent, but I don't know how.
I'm saw some wierd responses from Unity when I tried to do these actions :
1- I've created a Plane, simply rotated it (-32,-19,-56) and scaled it (3.21,1,2.43)
2- I've created a child cube for that plane and rotated it (-30,39,-78) and scaled it (3.54,4.8,6.42)
This is the final result in editor :
Did I do something wrong???
Why collider and renderer performing differently??
Is this a Unity bug? I'm currently using Unity 2017.3.1p1
Yes, it is some kind of bug.
To avoid it, don't child the objects directly to a non-uniformly scaled parent. Instead, child this non-uniform object (the cube) to an empty object, which will be the parent of the plane too.
Since an empty object is scaled 1,1,1, childing other objects to it don't cause this problem.
I have a parent SKSpriteNode which contains a number of child SKShapeNodes, SKSpriteNodes and SKLabelNodes arranged in specific X,Y position relative to the parent.
When I flip the parent by running an SKAction on it:
SKAction.scaleXTo(-1, duration: duration)
It flips the parent including the children (which I want) but the horizontal alignment of all the children nodes is randomized.
I must mention that I have
parent.anchorPoint = CGPoint(x: 0,y: 0)
The reason this is happening is because of your anchor point. Scaling (And all transformations) happens on this point. To test, take a piece of paper, put a pencil on the top left corner, then try moving the right side over to the left. leaving the pencil where it is. You will notice that the right side is now -width of the paper
What you need to do in this case, is add the width back in to keep the paper at the same location.
Same rule with the sprites. You have to add the width in when doing a negative scale, then remove the width when going back to a positive scale
(or just put your anchor in the center)
Geometrical transformation you apply to a node are automatically applied to its descendants.
This is why when you move/rotate/scale a node the children (and the grandchildren...) are updated as well.
If you want apply a transformation to your sprite without involving other nodes simply change the structure of you scene moving the children of your sprite like shown below.
As it is now
In this image the green circle is your sprite. In the left scenario when you change the green node, it's children are updated accordingly. And you don't want that.
As it should be
So move to the right scenario. Create a new SKNode (the orange one) and place it as shown below.
Now the green node has no children so you can apply geometrical transformation to it without any side effect.
I've looked around for some ideas on this to no avail. I have a scene in unity where a parent has four children positioned and rotated in relation to the parent (though not necessarily the same position and rotation as the parent). After moving and rotating the parent, the children should follow the parent, and reset their position and rotation in locally similar way to parent as before, preserving a similar formation. In particular, I can get the children to follow the parent, but once the parent reaches their destination, I don't know how to reset the children to their appropriate formation positions and rotations once the goal is reached. I'm not looking for someone to answer my question as much as a headstart on how to make this happen. Any help is greatly appreciated. Thanks everyone.
Assuming you have a script on your parent,
One approach will be to store the Transforms of the Children before the Parent starts to move and after reaching the destination, apply the Transform back to the children :)
[Child's transform is relative to the parent, so the child will be displaced if the parent is rotated since child is not at (0,0,0) relative to the parent]
I'm trying to position some gameObjects relative to it's parent. I'm using localposition, but the gameObjects are not placed well. If I use local position the parent's width is considered to be 1, right? So if I have a plane unity3d considers it to be a 1X1 square.
I tried to put some models in the local position (1, 1) but they are not placed in the top right corner of the plane...
Do you guys have some thoughts of what might be the problem?
You're incorrect: the parents' width is the x/y/z scale of the parent; local co-ordinates are still measured in world units. If your plane is 100x100 horizontally, and centred at 0,0,0 then you need to put the model to (50,0,50) to be at the corner.