Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to SetPrimaryPartCFrame() while preserving rotation WITHOUT MoveTo?

Asked by
nc2r 117
4 years ago

MoveTo changes the Y location to an unwanted value. The only option is SetPrimaryPartCFrame(), but this changes the orientation to an unwanted value. How should I proceed?

0
What is your code? NickIsANuke 217 — 4y

2 answers

Log in to vote
1
Answered by
AspectW 431 Moderation Voter
4 years ago

Give this a try:

model:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,0), model.PrimaryPart.Position))
0
Change 0,0,0 to your wanted position of course. AspectW 431 — 4y
0
ok nc2r 117 — 4y
0
ok nc2r 117 — 4y
0
Did it work? AspectW 431 — 4y
0
This will move the model to the desired location, but it will be pointed towards its last location chess123mate 5873 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

To preserve orientation, you have to add a Vector3 to the current CFrame:

local cf = model:GetPrimaryPartCFrame()
model:SetPrimaryPartCFrame(cf + Vector3.new(x, y, z) - cf.Position)

Vector3.new(x, y, z) - cf.Position gets the difference between where you want it and where it currently is. We add that difference to the current CFrame to get the correct position without changing orientation.

Answer this question