SOLUTION: This is quite long, so I thought I'd include the solution here. Basically, instead of rotation, we use the look vector as a multiplier. Script:
local newPos = Vector3.new()
local LV = template.Hitbox.CFrame.LookVector
newPos = pos + Vector3.new(LV.X * (template.Hitbox.Size.X) + padding, (template.Hitbox.Size.Y / 2), LV.Z * (template.Hitbox.Size.Z) + padding)
EDIT: I've played around with look vectors, however, with a rotation of 0,0,0, the models all generate one on top of the other. My experimental script:
local newPos = Vector3.new()
local LV = template.Hitbox.CFrame.LookVector
if LV.X ~= 0 then
newPos = pos + Vector3.new((template.Hitbox.Size.X / 2) + padding, (template.Hitbox.Size.Y / 2), 0)
else
newPos = pos + Vector3.new(0 + padding, (template.Hitbox.Size.Y / 2), 0)
end
print(LV)
if LV.X ~= 0 then
newPos = pos + Vector3.new(0, (template.Hitbox.Size.Y / 2), (template.Hitbox.Size.X / 2) + padding)
else
newPos = pos + Vector3.new(0, (template.Hitbox.Size.Y / 2), 0 + padding)
end
I think this would be better as rot would not be relied on, instead the model's direction. Could somebody fix this script ^^ to make it work? Now, the script down below seems obsolete.
So, I'm making a script to generate models. I currently have it to where I input a position and rotation, and it generates some models for an obby. I need it to dynamically update ,. However, my math seems to have failed me. Here is the equation I use to update the position, and I do this once before placing the model, and once after. My equation is such:
local newPos = pos + Vector3.new((template.Hitbox.Size.X / 2) + padding, (template.Hitbox.Size.Y), (template.Hitbox.Size.Z / 2) + padding)
I would do that once, then move the model:
model:SetPrimaryPartCFrame(CFrame.new(position) * CFrame.Angles(math.rad(rotation.X), math.rad(rotation.Y), math.rad(rotation.Z)))
Then do that again.
I should probably show you what's wrong. Here's a rotation of 0, 0, 0.
As you can see, It's super glitched. Instead of generating correctly in a straight line, they generate in a diagonal. Help?

7 comments
Could you show what your original model looks like?
Well they are randomly generated
Out of a folder
But u can see some in the imgur link.
I think it would be useful to see the structure of the model as well as some of the properties.
The only relevant things are the model itself and the hitbox: https://imgur.com/a/vg9WgxW
The hitbox is the size of the model, with the Y set to 1. Unless it is a vertical stage, in which case the height is the height of the stage.