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

Trying to tween the CFrame of a model?

Asked by 3 years ago
Edited 3 years ago

I'm working on my own custom placement system, and I thought it would be nice to have the model smoothly move between points with the mouse. I am struggling trying to figure out how to move the whole model. My current code is:

local TweenService = game:GetService("TweenService")
local TI = TweenInfo.new(0.05, Enum.EasingStyle.Quad)

local newTween = TweenService:Create(currentModel.PrimaryPart, TI, {CFrame = cf})
newTween:Play()

Please note, I did not show the full code here. CurrentModel is the model I am trying to move. cf is the Frame I am trying to move it to.

The problem is, this ONLY moves the primary part of the model. Can someone help?

0
Maybe you coul add a motor6D / Weld to connect every part in the model with this plugin https://web.roblox.com/catalog/804263305/Constraint-Editor ZIRFAL3 17 — 3y

2 answers

Log in to vote
1
Answered by
ben0h555 417 Moderation Voter
3 years ago
Edited 3 years ago

Try using TweenService:GetValue() in combination with a loop that calls the method SetPrimaryPartCFrame() with a lerped cframe instead!

local TweenService = game:GetService("TweenService")
local Time = time() --Gets the starting value of time.
local Total = 1 --How many seconds till completion
local Model = workspace.Model --Location of model
local Start = Model:GetPrimaryPartCFrame() --Starting cframe to lerp with.
local End = CFrame.new() --End cframe to lerp to.
while time() - Time <= Total do --Will keep looping until beyond timeframe
    local TI = TweenService:GetValue((time() - Time)/Total, Enum.EasingStyle.Quad, Enum.EasingDirection.In) --Gets the value for which to lerp the cframe with.
    local CFrame2 = Start:Lerp(End,TI) --Gets the CFrame between start and end
    Model:SetPrimaryPartCFrame(CFrame2) --Sets the model's CFrame.
    wait() --Makes sure the game doesn't crash.
end
0
There has to be an easier way to do this, this seems overly complicated. This works for now, but I may seek a different solution in the future. NickIsANuke 217 — 3y
0
Honestly I feel like this is one of the easiest ways to do it, the stuff that involves welds and motor6ds tends to require more preparing and adding stuff you wont need later ben0h555 417 — 3y
Ad
Log in to vote
-2
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago

Mhhhhh... i have done something like this some time ago and did not work too and that's stupid imo.

Anyways what you could do to fix it keep the primary part anchored and for other parts use Weld Constraints to weld them to the primary part, also make sure they are not anchored.

0
aww the downvotes... DiamondComplex 285 — 3y
0
i know right ahaha          give me one more imKirda 4491 — 3y

Answer this question