Issue Tweening a Character Model

Hello,

I have the feeling that I am missing something really basic, but spent some time reading and trying things out and ended up nowhere… so hopefully you can throw some light.

What I want to do?
I have a 3d model character rendered on my UI, inside a ViewportFrame and I’m trying to keep this character rotating on the Y axis.

Here’s my code:

local classSelectionGUI = PLAYER_GUI:WaitForChild("ClassSelection")
local classOneViewport = classSelectionGUI.ClassContainer.ClassOne.Viewport

-- Class One Model
local classOneModel = REPLICATED_STORAGE.items.classes.class01:Clone()
classOneModel.PrimaryPart.Position = Vector3.new(0,0,0)
classOneModel.Parent = classOneViewport

-- Class One Camera
local classOneCamera = Instance.new("Camera")
classOneCamera.CFrame = CFrame.lookAt(Vector3.new(0,1,6), Vector3.new(0,0,0))
classOneViewport.CurrentCamera = classOneCamera

-- Class One Tween
local tweenOneConfig = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local tweenOne = TWEEN_SERVICE:Create(classOneModel.PrimaryPart, tweenOneConfig, {Orientation = Vector3.new(0,360,0)})

tweenOne:Play()

The character renders as expected, but no tween seem to be happening since the character stay still.

One thing that I noticed when I was trying to better position my character (model) is that the line:

classOneModel.PrimaryPart.Position = Vector3.new(0,0,0)

Doesn’t seem to have any effect as I tried to move it by giving a different Vector3 and nothing really happened.

Other than that everything looks ok to me and I really don’t know what to try next. So your help is very much appreciated.

Put a world model into the viewport frame and then put the model in the world model if you haven’t already.

I just did it, and it noticed that now my character is playing idle animation, which is great… you solved a problem I would have ahead, so thanks for that.

The Tween still not happening though :frowning:

EDIT: Also noticed that now I can position my character (model) with the line that previously wasn’t working.

Try this:

local classSelectionGUI = PLAYER_GUI:WaitForChild("ClassSelection")
local classOneViewport = classSelectionGUI.ClassContainer.ClassOne.Viewport

-- Class One Model
local classOneModel = REPLICATED_STORAGE.items.classes.class01:Clone()
classOneModel.PrimaryPart.Position = Vector3.new(0,0,0)
classOneModel.Parent = classOneViewport

-- Class One Camera
local classOneCamera = Instance.new("Camera")
classOneCamera.CFrame = CFrame.lookAt(Vector3.new(0,1,6), Vector3.new(0,0,0))
classOneViewport.CurrentCamera = classOneCamera

-- Class One Tween
spawn(function()
while task.wait(0.001) do
local ModelCFrame = classOneModel:GetPrimaryPartCFrame()
ModelCFrame *= CFrame.Angles(0,0.05,0)
classOneModel:SetPrimaryPartCFrame(ModelCFrame)
end
end)
1 Like

I got it “working” by changing the code inspired on your suggestion:

local tweenOneConfig = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true, 0)
local goal = {}
goal.CFrame = classOneModel.PrimaryPart.CFrame * CFrame.Angles(0,360,0)
local tweenOne = TWEEN_SERVICE:Create(classOneModel.PrimaryPart, tweenOneConfig, goal)

Despite the fact I’m pushing for 360 rotation the model only rotates 90 degrees, not sure what I am missing.

change:

goal.CFrame = classOneModel.PrimaryPart.CFrame * CFrame.Angles(0,360,0)

to:

goal.CFrame = classOneModel.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(360),0)

or:

goal.CFrame = classOneModel.PrimaryPart.CFrame * CFrame.FromEulerAnglesXYZ(0,360,0)

Thanks again for the quick reply.

The approach with math.rad makes the model stay still while the one with fromEulerAnglesXYZ yields the same results of the current implementation :frowning:

Try this:

local tweenOneConfig = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, true, 0)
local goal = {}
goal.CFrame = classOneModel.PrimaryPart.CFrame * CFrame.Angles(0,1440,0)
local tweenOne = TWEEN_SERVICE:Create(classOneModel.PrimaryPart, tweenOneConfig, goal)

My reply may send twice cause my wifi was being weird when i sent it the first time.

Hey man, thanks again.

Did some good reading and looks like the Tween always find the shortest path to execute.

What did work so far was:

local tweenOne = TWEEN_SERVICE:Create(
    classOneModel.PrimaryPart,
    tweenOneConfig, 
    { CFrame = classOneModel.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(120),0) }
)
local tweenTwo = TWEEN_SERVICE:Create(
    classOneModel.PrimaryPart,
    tweenOneConfig, 
    { CFrame = classOneModel.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(240),0) }
)

local tweenThree = TWEEN_SERVICE:Create(
    classOneModel.PrimaryPart,
    tweenOneConfig, 
    { CFrame = classOneModel.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(360),0) }
)

tweenOne.Completed:Connect(function() 
    print("one finished")
    tweenTwo:Play()
end)

tweenTwo.Completed:Connect(function() 
    print("two finished")
    tweenThree:Play()
end)

tweenThree.Completed:Connect(function() 
    print("three finished")
    tweenOne:Play()
end)

For now it’s okay, but there must be a better or cleaner way to do it… I’ll keep the topic opened.

But really appreciate the help so far @os_clock

1 Like

I have a cleaner way to do it:

for i=0,360,120 do
local tween = TWEEN_SERVICE:Create(
    classOneModel.PrimaryPart,
    tweenOneConfig, 
    { CFrame = classOneModel.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(i),0) }
)

tween:Play()

tween.Completed:Wait()
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.