decentraland / creator-hub

MIT License
0 stars 4 forks source link

Function for local>world position & rotation #171

Open nearnshaw opened 1 year ago

nearnshaw commented 1 year ago

It's a very common use case to want to convert the position of a nested entity (relative to the parent) to an absolute position relative to the scene's 0,0,0.

Currently in SDK6 we have a function for that in the Utils library, but such a common task should be part of the base SDK, not relying on installing extra libraries.

See these functions https://github.com/decentraland/decentraland-ecs-utils#world-position https://github.com/decentraland/decentraland-ecs-utils#world-rotation

We need a function to obtain the world position and another to obtain the world rotation. These functions would take a single entity as an argument, and also allow for a second optional argument to provide an offset, for example getWorldPosition(myEntity, Vector3.create(1,0,0) to get the position immediately in-front of an entity.

In the most simple of cases, we check for parent entities and offset any position, rotation & scale. But if we're doing this as part of the SDK, maybe we can even do more powerful things engine-side, to include animations too.

For example for entities attached to a player we should involve the player position, and even (nice to have) any translation from player emotes.