In Roblox Studio there’s this “Reset” button
Now, the issue was that I had to press it twice. Shouldn’t you just have to press it once?
So why did I had to press it twice? Well, I actually didn’t have to, I could have just pressed it just once. But when I pressed it again, it moved again, this means that the Pivot wasn’t exactly reset.
So why wasn’t the pivot reset when pressing on “Reset” at the first try?
It had to do with the BoundingBox of the model or just GetBoundingBox()
.
I tried to reproduce the issue, but not sure. It was basically a “Model” that had a lot of stuff inside of it, like MeshParts and stuff.
However, for the issue, you can basically look at the code from this thread here, and use it. Reset WorldPivot of Objects
This code causes the same issue. You would have to run it twice, for the Model’s WorldPivot to be reset properly, or just once, depends on what your model contains. But there’s a case where you have to run it twice like that.
However, not if you change the code to the following:
local BoundingBoxOrientation = value:GetBoundingBox()
value.WorldPivot = CFrame.new(BoundingBoxOrientation.Position)
BoundingBoxOrientation = value:GetBoundingBox()
local WorldPivotAngles = CFrame.fromAxisAngle(value.WorldPivot.LookVector, 0)
value.WorldPivot = CFrame.new(BoundingBoxOrientation.Position) * WorldPivotAngles
This code here, resets the pivot properly, and the code does not have to be ran twice, just once. You will notice that I change the model’s WorldPivot position first and then get the bounding box again.
And yeah, that is correct. In certain cases, where you have a model within a model with many parts, or just a model with many parts, it can occur that apparently there seems to be issues calculating the things correctly, not sure.
What the quoted code does is, it gets the bounding box of the model’s current rotation and position. Then a new angle is being calculated and then put together.
However, it seems that this “GetBoundingBox()” doesn’t seem to be very “safe” to just use it once, and that’s why it wasn’t reset properly.
It seems that every operation with a model BoundingBox, if the BoundingBox changed, like the model being moved or rotated, that it has to be updated as in either use GetBoundingBox()
directly, or overwrite the variable.
The Studio bug seems to be that it is also just getting the BoundingBox once, and then changes the position and the rotation all together and that’s why when I clicked on reset for the second time, the pivot position changed again. While I expected it to not change, because it was ment to be reset completly, with just one click, which wasn’t the case.