Open AufderWelt opened 4 years ago
Alternate work-around You can get at this scale without going through the Component API by using:
local function getObjectTransformScale(obj)
local rotation = obj.getRotation()
local onesVector = Vector(1, 1, 1):rotateOver('z', rotation.z):rotateOver('x', rotation.x):rotateOver('y', rotation.y)
local scale = obj.positionToLocal(obj.getPosition():add(onesVector))
return scale
end
@Benjamin-Dobell the scale needs to be divided by 1, or? to get the same scale vector, which you get by the call obj.getScale()
@AufderWelt Yeah, sorry, what I posted was the inverse scale of localScale, as that's just what I happen to use more frequently. If you want to directly calculate localScale
I believe the following ought to do it:
local function getLocalScale(obj)
local rotation = obj.getRotation()
local onesVector = Vector(1, 1, 1):rotateOver('y', -rotation.y):rotateOver('x', -rotation.x):rotateOver('z', -rotation.z)
local scale = obj.positionToWorld(onesVector):subtract(obj.getPosition())
return scale
end
If you happened to grab that right after I posted, I've just reversed the order of the rotateOver
calls, as I believe this is correct now.
Admittedly, I've not really tested this, so may want to give it a go on some objects with different scalars for x, y and z components of the scale.
Describe the bug the call
generates an error, if the object does not contain lua code. the call works, if the obj contains some lua code, for example "--"
To Reproduce opend a new singleplayer table. put this code in the Global
Expected behavior the
obj.getComponent("Transform").get("localScale")
should work, without the object containing lua codeTabletop Simulator Info:
Known workarounds if lua code are injected into the object, the call works
Additional context the call
lua obj.getComponents()[1].get("localScale")
does not work. it does not matter, if the object contains lua code or notLink to TTS post https://forums.tabletopsimulator.com/showthread.php?8928-obj-getComponent(-quot-Transform-quot-)-get(-quot-localScale-quot-)-access-error&p=28926#post28926