[SOLVED] Same child size regardless the size of the parent

I have parent entities with different sizes, that all has a child that has to be the same size.

I think the best solution is to calculate the size for the child in the initialize based on the size of the parent and the desired size.

Anybody an idea how to do this?

Hi @Albertos,

This thread I think continues a solution for that:

Hay @Leonidas! I tried, but I think it’s a diffrent case. This is my setup:

  • Rifle (parent, scale 0.6, no script)

    • Item (child, scale 1.0, with item script)
  • Stone (parent, scale 0.15, no script)

    • Item (child, scale 1.0, with item script)

I’d say since the scale is always in local units, you need a reference size in world units.

You could calculate the total bounding box size for your child entity initially, and then use that to calculate the required local scale each time.

So it matches that bounding box.

1 Like

Thanks @Leonidas! With the help of @LeXXik this solved my problem:

    var currentScale = this.entity.parent.getLocalScale();
    var desiredScale = new pc.Vec3(2, 2, 2);
    var newScale = this.entity.getLocalScale();
    var factor = desiredScale.x/currentScale.x;