[Solved] Incorrect local coordinate translation when using multiple components
Posted: Tue Jan 28, 2020 11:15 pm
I ran into this issue while working on a lua specialization script for a mod. Here's the (much simplified) outline of the issue:
1. the lua script reads two node paths from a vehicle XML config key.
2. Next, it uses retrieves the nodes:
3. The world coordinates are retrieved:
4. The local coordinates relative to node2 are retrieved by using
When node1 and node2 are part of the same component, this works beautifully.
But if they are part of two different components in the XML, the worldToLocal() call produces the wrong coordinates.
To make sure, I also tried this with node1 being a completely different object in-game. In that case, the expected results are returned.
1. the lua script reads two node paths from a vehicle XML config key.
2. Next, it uses retrieves the nodes:
Code: Select all
node1 = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile,"path.to.my.key#node"));
node2 = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile,"path.to.my.key#baseNode"));
Code: Select all
local xWorld, yWorld, zWorld = getWorldTranslation(node1)
Code: Select all
local xLocal, yLocal, zLocal = worldToLocal(node2, xWorld, yWorld, zWorld)
But if they are part of two different components in the XML, the worldToLocal() call produces the wrong coordinates.
To make sure, I also tried this with node1 being a completely different object in-game. In that case, the expected results are returned.