Setting model position with changed pivot

I’m having an issue with a script that is updating parts and models to new versions. The issue that I’m running into is that all the new models have pivot offsets which are not zero. Because of this, the models are off the ground by the pivot amount. Here is the code that I’m using for both parts and models:

if model == true then
	-- Model
	local mpp = ammo.PrimaryPart.PivotOffset.Position + pos
	local cf = CFrame.new(mpp) * CFrame.Angles(ox, oy, oz)
	aclone:PivotTo(cf)
else
	-- Part
	local ppo = ammo.PivotOffset.Position
	aclone.Position = pos + ppo
	aclone.Orientation = orient
end

And this is the result:

As you can see, the item on the right is levitated off the ground by 1/2 the vertical size of the model. The pivot points on all the new models is at the bottom of the model. The actual number varies for each model. The pivot of the original models is at (0, 0, 0). What is interesting is that the code for part is working correctly. Now I read that models use the pivot of the primary part, and what’s what I’m using, but it’s not working. It’s at the position of the original model with the pivot position offset set to (0, 0, 0). How do I fix this?

pos is the position of the original model.

I am running this from a script on the command line in studio. There’s a bunch of models that needs to be replaced and this was the easiest way to do it.

Try something like model:PivotTo(cf * model.PivotOffset:Inverse())

That didn’t work. But I did figure it out on my own. I made some changes to the code. It now reads as follows:

if model == true then
	local cframe = ammo:GetPivot()
	local poff = aclone.PrimaryPart.PivotOffset
	local cf = cframe * poff
	aclone:PivotTo(cf)
else
	local cframe = ammo.CFrame
	local poff = aclone.PivotOffset
	local cf = cframe * poff
	aclone:PivotTo(cf)
end

The problem was that I was pulling the pivot position from the old model and not the new one. That code now works correctly.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.