Getting Entity's LocalPosition Within Another Entity's Localspace

Hi all,

Slightly confusing title, but the concept is simple, and probably best explained with an image:
LocalPosExample
What I’m looking for is to find the blue entity’s localposition in the red entity’s localspace. In this case, if it were a function, I’d want to find the blue entity’s location, and the ideal return coordinates would be (100, -100).

In Unity, I could achieve this via

redEntity.transform.InverseTransformPoint(blueEntity.parent.TransformPoint(blueEntity.localPosition));

But due to some changes in hierarchy, it doesn’t perfectly translate, even if I knew which functions I should be using.

I’ve explored somewhat with getWorldTransform(), getLocalTransform(), invert(), and transformPoint(), but none of them seem to get me toward what I’m looking for.

Any assistance would be appreciated, thanks.

Hi @TingleyWJ,

I think subtracting their world positions will get you what you need:

    this.vec = new pc.Vec3().copy(blueEntity.getPosition());
    
    this.vec.sub(redEntity.getPosition());

    console.log(this.vec);