- What are you attempting to achieve? (Keep it simple and clear)
Copy a model (which has a PrimaryPart set) server storage, and keep its orientation (so it stays the right way up), and then later, rotate it on the Y axis.
- What is the issue? (Keep it simple and clear - Include screenshots/videos/GIFs if possible)
**When I copy a model from Server Storage, it doesn’t keep its original orientation. (fixed, but with side-effects) ** We have to use :ToOrientation() to get the rX,rY,rZ and re-apply it. That’s easy enough, although it’s annoying there a simple ‘keep orientation’ way to copy. But it also keeps its pivot-offset-orientation, which means, any future orientations of the object (for example to turn in 90 degrees on Y) means that the action occurs on an unpredictable axis. So instead of rotating as it stands, it’ll go lay sideways or face upwards (i.e. a X or Z rotation).
How do take a model in Roblox Studio and ‘normalize’ it so that its current orientation and pivot are all reset to zeros, so it behaves normally when copied & rotated later? Or, how do I take into account the Pivot Orientation of a model so that I can correct the rotation axis and rotate it on the axis I want?
(Beforeone any asks, ‘behaves normally’ means when I want an Y-axis rotation, then, it rotates on the Y-axis, because, its pivot-orientation is now nicely reset/normalized).
- What solutions have you tried so far?
There are a great many posts on orientation, and several that say it is simply impossible, but, I’m hoping that they’re wrong. Some of those posts helped me get past the first problem (that cloning an object doesn’t keep its orientation). Most say the best solution is not to use Roblox Studio to design models, so that they can be ‘re-exported’ but with normalized orientation. As these models are actually just in Roblox Studio, I need either a plugin to normalize orientations, or a programmatic way of doing it.
I’ve tried some plugins like ‘XYZ Fixer’ but either they don’t work any more, or, they don’t do the precise and rather common thing of fixing orientation.
Green,Red,Blue arrows: In Roblox studio, I’ve taken a part that is oriented naturally, with the green orientation arrows vertical etc, and, modified a model’s Pivot Orientation until its own green, red & blue arrows are in precisely the same configuration. Therefore, after copying it, any rotations should apply on precisely the correct axis. But it just doesn’t work; I’m finding it impossible to predict what axis a rotation will apply to. The only solution is to rotate the original model and then reset/normalize all of its orientations to 0,0,0 so it copies completely naturally, but, there’s no way to do that in Studio. The absolute worst is going to be to manually rebuild models with a different orientation, but… it’s 2024, and Roblox Studio isn’t new anymore, and there simply has to be a sensible way to do it.
I’ve got one function that clones objects, and another one that moves them.
Cloning: The models go onto (basically) a 2D map, where only X and Z matter, using a grid co-ordinate system. I pass to this an initial ‘rotation’ option, for example, ‘90’, so the items (similar to user-led Furniture-Placement Systems) face the right way. All rotations are therefore just on the Y axis.
function cloneModelToRm (pModelRef,pX,pZ,pRotateInDegree)
local rX,rY,rZ = pModelRef.PrimaryPart.CFrame:ToOrientation() --get the orientation of the model in storage (need to preserve & re-use it seperately to the clone)
local lModel = pModelRef:Clone()
wait(1)
moveModel(lModel,pX,pZ,pRotateInDegree,CFrame.Angles(rX,rY,rZ))
lModel.Parent = self.wsFolder.rooms[pRoomId]
return lModel
end
And here’s the bit that rotates them in accordance with its original orientation in storage, plus whatever the user has dictated for this particular item - after cloning, pOrientation is not used):
function moveModel(pModel,pX,pZ,pRotateDegrees,pOrientation)
-- User can rotate it on its Y axis in 90-degree steps (passed as pRotateDegrees)
-- pOrientation is the CFrame*3 angles used to orientate the whole thing when cloning it from storage
local lCFrame
lCFrame = plrGridsToCFrame(pRelToPlr,pX,pZ,8)
if pOrientation then lCFrame = lCFrame * pOrientation end -- pOrientation is the CFrame*3 angles used to orientate the whole thing when cloning it from storage
if pRotateDegrees then
lCFrame = lCFrame * CFrame.Angles(0,pRotateDegrees*(math.pi/180),0) -- For user rotations of tables
end
pModel:SetPrimaryPartCFrame(lCFrame)
end
The code is a bit messy and I’m going to combine some of the transforms later (but can’t do it until I’ve worked out the issues, else I’ll never work out at what stage things are going wrong).
What I need to do … in moveModel to be able to determine how to change the * CFrame.Angles(x,y,z) so that Y-axis rotations (in degrees, passed as the pRotateDegrees parameter) occur ON the Y-axis. I’ve spent all day trying to manipulate this, and everytime I have a partial solution, I find that it only works in one particular solution, on one particular model.