# Scaling and positioning child nodes

Hi everyone,

I’m trying to get the following effect: a character with separate parts, in which each part scales independently.
I made a picture (in 2D) of what I’m trying to get, after I realized I couldn’t understand my own explanation:

In this case, I’m trying to get the limbs to be positioned relative to the trunk, but also taking its scale into account.

My current try is to have a parent node which is the “trunk” to which the other parts are attached. I can scale them independently, but that messes up the positioning.

Also, it doesn’t have to be pretty. I’ll worry about pretty later. For now, consider that the trunk and the parts attached are cubes that’ll be scaled.

Can you think of a way of solving it, or suggest a better way of achieving some effect along those lines?

Thanks.

You could probably achieve this by smartly using a CompassEffect in the PScale setting. It’d get a bit complicated though, so perhaps it would be easier to create a task that calculates the correct position and scale for the individual limbs.

Well, if I understand right the only problem is that - because of the scene graph structure - the scale applied to the trunk is also applied to the limbs and their positioning (if you apply a scale of 1.5 to the trunk, then this scale is also applied to every child’s transform, which is position and scale!).

One solution would be to restructure the scene graph like this:

``````PandaNode "object root" (scale=1)
GeomNode "trunk" (scale=1.5)
GeomNode "limb1" (scale=2.5, pos=...)
GeomNode "limb2" (scale=2.5, pos=...)``````

Thanks. It didn’t solve my problem but it was part of the solution.

I managed to do it using getTightBounds in order to do “absolute” positioning. I imagine this can be a problem at some point, but so far it’s working for my purposes.

 Bah, sorry - I accidentally hit “submit” instead of “preview” - real post coming soon, I intend. ^^;;;

[edit 2] Right, the actual post:

Forgive the lateness of my comment, but a thought occurred to me that might work without using calcTightBounds:

• Create a class to wrap parts; each would contain a part, a reference to its parent and a list of references to its children.
[list][]Note! This creates a circular reference for non-trivial objects, I believe; be careful to clean these up properly!
[/
:m]
[*]Each part is then given a position relative to its parent, not in absolute terms, but rather the proportional terms; that is to say, coordinates that are each some percentage of the parent’s dimensions.
• For example, presuming z-up: an arm is most of the way up a body, roughly centred laterally, and all the way to the side, giving us coordinates something like (1.0, 0.5, 0.9)
[/:m]
[
]When a part is scaled (and to this end I recommend a function in your class to handle scaling, rather than scaling the NodePaths directly), parts that depend on it are re-positioned accordingly, based on their proportional positions.[/:m]
[
]Finally, one special case: legs. Since they are bound at the bottom by the floor, the body should go up when they extend; perhaps have legs re-position themselves and their parents after scaling.[/*:m][/list:u]

I have it working now, but having a wrapper class might be useful.
I’m just starting this project, so I don’t know in details how I’m going to implement each feature I have in mind - I tend not to do a lot of planning as to implementation (which partially explain the amount of unfinished projects I have).

Right now I just need to do this scaling-and-positioning once, then use the result.

Currently, I do legs first, then position everything else, so that it’s on the floor.