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

How to cframe a model to another bricks position?

Asked by 6 years ago

Hey,

So I have this Cframe script, using this same script, how can I make it so that it moves to another bricks position. This script will Cframe the whole model and I would like to keep it that way.

Thanks!

function onClicked()
    wait()
    for i = 0, 10, 0.2 do
    game.Workspace.Pie:SetPrimaryPartCFrame(game.Workspace.Pie:GetPrimaryPartCFrame() + Vector3.new(game.Workspace.Part.Position))
wait()

end
end 

script.Parent.ClickDetector.MouseClick:connect(onClicked)

2 answers

Log in to vote
0
Answered by
PolyyDev 214 Moderation Voter
6 years ago

I don't quite understand if you are trying to get the part to ease into a position smoothly. If you are then look on YouTube for Roblox's new TweenService.

If not and your just trying to make it snap to position then you would do this:

local pie = game.Workspace.Pie
local part = game.Workspace.Part

pie:MoveTo(Vector3.new(part.Positon)) -- Or you could just put the position of the part inside the Vector3.

-Ki_ngPhantom

Ad
Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Well first make sure the PrimaryPart is set. Let's use the lerp function of CFrame to move it

Let's set up some variables

local endpart=workspace.End
local model=workspace.Model

Next let's get ready for the lerp

local upby=.005

Here's the lerp part, Basically lerp is like taking a points between two cframes and moving it to each point, 'i' is the position between each cframe, i ranges between 0 and 1.

for i=0,1,.005 do wait()
    model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame():lerp(endpart.CFrame,i))
end

Let's put it together

local endpart=workspace.End
local model=workspace.Model
local upby=.005
for i=0,1,upby do wait()
    model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame():lerp(endpart.CFrame,i))
end

There you go your model will lerp to the end cframe. you can change the orientation of the model by adding *CFrame.Angles(0,0,0) to the right of endpart.CFrame.

Answer this question