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

How do I orientate my anchored model in workspace?

Asked by 1 year ago
Edited 1 year ago

I've got a model in workspace (anchored) that I want to move, however I can't seem to orientate it. I've tried using bodygyros for a smooth orientation, but It didn't work because the model is anchored. I found a solution using a dummy cframe and setting the cframe of my model.

local cframe = Instance.new("CFrameValue") -- create a dummy cframe value to tween
            cframe.Value = tower:GetPrimaryPartCFrame() -- set to current model's cframe to tween from current cframe
            cframe:GetPropertyChangedSignal("Value"):Connect(function(value) -- listen for the dummy cframe to change, and update model's cframe
                tower:SetPrimaryPartCFrame(value)
            end)

            local targetCF = CFrame.lookAt(tower.PrimaryPart.Position, target.PrimaryPart.Position)
            -- tween dummy cframe value, and the Changed listener will move the model smoothly
            local tween = game:GetService("TweenService"):Create(cframe, TweenInfo.new(0.1), {Value = targetCF}) -- change to however you want to tween the model
            -- destroy the dummy cframe after the tween to prevent memory leaks
            game:GetService("Debris"):AddItem(tween, 0.2)

However, my model still doesn't orientate, which is annoying...

Answer this question