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

How do I set Rotation with models using SetPrimaryPartCFrame??

Asked by 8 years ago
Edited 8 years ago

I've figured out how to set the position, but it always changes its rotation from its initial one.

Here's the guilty part of my tools script

        fakeBoat = boatModel:clone()
        fakeBoat.Parent = workspace
        fakeBoat.PrimaryPart = fakeBoat.redBoat 
            mouseMoved = mouse.Move:connect(function()
                if mouse.Target.Name == "Water" then
                fakeBoat:SetPrimaryPartCFrame(CFrame.new(mouse.Target.CFrame.X,mouse.Target.CFrame.Y,mouse.Target.CFrame.Z))
                end
            end)
        end
    end
end

assume the rest of this works, because it does. It moves with this script based on my cursor, but the "fakeBoat" rotation is always 0, 0 , 0 i think.

2 answers

Log in to vote
1
Answered by
Fatul 9
8 years ago
Edited 8 years ago

Use Angles.

fakeBoat:SetPrimaryPartCFrame(CFrame.new(fakeBoat.PrimaryPart.Position) * CFrame.Angles(0,math.pi/2,0))

Ad
Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

If you want to preserve the rotation of the boat, you will have to get the existing rotation before you move it, then add it on to the position.
The way you would do it is like this:

local previousRotation = fakeBoat:GetPrimaryPartCFrame() - fakeBoat.PrimaryPart.Position
fakeBoat:SetPrimaryPartCFrame(CFrame.new(mouse.Target.Position) * previousRotation)

You may also wish to consider using mouse.Hit.p rather than mouse.Target.Position, but I'm not sure this fits with your specific case.

Hope this helps!

Answer this question