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

How can I preserve orientation of my model while moving it with TweenService?

Asked by 5 years ago

I'm building a set of sliding doors that use TweenService when I press a button to trigger them. There are two positions (opened and closed) that are represented using four invisible, massless and non-CanCollide bricks, which are identical to the real doors. (Door1Closed, Door1Opened, Door2Closed and Door2Opened)

Both doors are models, so I built a function ('tweenModel' in the code) to tween every part in the model independently rather than using SetPrimaryPartCFrame(), because it caused trouble with special welds elsewhere in my game.

It works, but it also tweens to an orientation of {0, 0, 0}. Somebody mentioned that the problem stems from CFrame including orientation values as well as position, and me calculating CFrame from Vector3 (Position), gives it no values for orientation, causing it to resort to the default (which I assume is {0, 0, 0})

If this is the case, then how can I keep the orientation of my doors while using TweenService to translate them?

Here's a video of the doors: https://imgur.com/qjWnSsO

Here's the script:

01local TweenService = game:GetService("TweenService")
02local Door1 = script.Parent:WaitForChild("Door1")
03local Door2 = script.Parent:WaitForChild("Door2")
04local Targets = script.Parent.Targets
05local tweeningInformation = TweenInfo.new(
06    1,
07    Enum.EasingStyle.Bounce,
08    Enum.EasingDirection.Out,
09    0,
10    false,
11    0
12)
13 
14local Open = true
15local OpenButton = script.Parent:WaitForChild("OpenButton")
View all 58 lines...

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

If you want to keep the orientation, you can simply replace the CFrame field in the properties table with Position so the third argument when you are creating the tween would be something like {Position = descendants[i].Position + vector}

0
Thanks, it works perfectly now! nikoviking 236 — 5y
Ad

Answer this question