I am trying to move a model to the left of another model. How could I achieve this?
Could you perhaps specify what you mean by this?
How would I specify what I mean?
I am trying to move a model to the left of another model no matter which way it is facing.
Okay so here’s the code, just change it to suit you. Also don’t forget to set the primary parts of both models.
local TargetModel = [WHATEVER YOU'RE TRYING TO MOVE]
local MoveToModel = [WHATEVER YOU'RE TRYING TO MOVE THE TARGET TO THE LEFT OF]
TargetModel:SetPrimaryPartCFrame(MoveToModel:GetPrimaryPartCFrame() * CFrame.new(-5,0,0))
You can move a CFrame relative to another CFrame like this: WorldSpaceOriginCFrame:ToWorldSpace(ObjectSpaceOffsetCFrame)
.
For example, this results in a CFrame 10 studs to the left of the OriginModel:
OriginModel.WorldPivot:ToWorldSpace(CFrame.new(-10, 0, 0))
This is the same, but you can select which axis will be changed. Just edit the USE_AXIS
constant. In the snippet below, it’s set to keep the Y axis.
local MOVE_VECTOR = Vector3.FromNormalId(Enum.NormalId.Left)
local USE_AXIS = Vector3.new(1, 0, 1)
local MOVE_DISTANCE_STUDS = 50
local OriginModel = workspace.Rig
local MoveModel = workspace.House
local function flip(x)
return x == 1 and 0 or 1
end
local KeepAxis = Vector3.new(
flip(USE_AXIS.X),
flip(USE_AXIS.Y),
flip(USE_AXIS.Z)
)
local RelativePivot = OriginModel.WorldPivot:ToWorldSpace(CFrame.new(MOVE_VECTOR * MOVE_DISTANCE_STUDS))
local MergedPivot = CFrame.new(MoveModel.WorldPivot.Position * KeepAxis + WorldOrigin.Position * USE_AXIS) * WorldOrigin.Rotation
MoveModel:PivotTo(MergedPivot)
Before
After (Left)
After (Top)
Isn’t :SetPrimaryPartCFrame being deprecated?
Thank you so much! I am very close to what I am intending, but the first model has orientation that I don’t want the second model to inherit. How could I do this?
You simply have to remove this part.
Ok, but how can I remove the orientation from this OriginModel.WorldPivot:ToWorldSpace(CFrame.new(-10, 0, 0))
You can make use of the OriginModel.WorldPivot:PointToWorldSpace(Vector3.new(-10, 0, 0))
function, or use the Position property of CFrames, like this:
OriginModel.WorldPivot:ToWorldSpace(CFrame.new(-10, 0, 0)).Position
.
Model:PivotTo(CFrame.new((Model.WorldPivot * CFrame.new(-10, 0, 0)).Position))
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.