Tween part bug CFrame

Hello, i’m trying to Tween a model and it worked but this gave me that issue :
image
instead of that :
image
I didnt provide any rotation or something else in the script :thinking:

local TweenService = game:GetService("TweenService")

local TargetPositionD1 = CFrame.new(287.399, 21.369, 41.619)

local TargetPositionD2 = CFrame.new(144.487, 21.609, 41.618)

local PartSlideInfoDoorsLR = TweenInfo.new(

5, --- Time to tween from position to position (in seconds, default is 4 seconds)

Enum.EasingStyle.Linear,

Enum.EasingDirection.InOut,

0, --- Times repeated. If set to -1, it will loop the tween indefinitely. (default is 0)

false, --- Reverse the tween or not (default is false)

0 --- Delay time, default is set to 0.

)

local PartSlideTweenD1 = TweenService:Create(script.Parent.Parent.Door.D1.PrimaryPart, PartSlideInfoDoorsLR, {CFrame = TargetPositionD1})

local PartSlideTweenD2 = TweenService:Create(script.Parent.Parent.Door.D2.PrimaryPart, PartSlideInfoDoorsLR, {CFrame = TargetPositionD2})

wait(3)

PartSlideTweenD1:Play()

PartSlideTweenD2:Play()

You can’t tween models, your best bet would instead to tween a cframe value, and then have a changed signal on the CFrame value, that then changes the CFrame of the model using PivotTo().

It’s possible just make PrimaryPart other parts unanchored and weld them to the Prim and tween it, others already did it but i got bug with Position then i need to do it with CFrame.

The change in rotation is caused by the fact that when you created the new target position CFrames TargetPositionD1 and TargetPositionD2, you didn’t provide an orientation, so the rotation was set to (0, 0, 0) by default. You can get around this by creating the target CFrames based on a relative offset from the original CFrame, for example:

local TargetPositionD1 = D1.PrimaryPart.CFrame + D1.PrimaryPart.CFrame.RightVector*5
local TargetPositionD2 = D2.PrimaryPart.CFrame - D2.PrimaryPart.CFrame.RightVector*5

Edit: The number you multiply the vector (and also which vector you should use) depends entirely on your model, so you’ll have to try what works for you.

2 Likes

You’re not defining an angle for the CFrame, the way I tend to CFrame multiple parts is having the primary part duplicated and having ‘StartStates’ and ‘EndStates’, and then I tween them to the CFrames of those respective parts, you can also add in *CFrame.fromEulerAnglesXYZ or *CFrame.Angles,

At the moment, when you’re CFrame is being actioned it is putting its angle at the default angle, as you’re not defining one.

^ what @TenX29 says

i don’t believe you can just tween the PrimaryPart and it would work,

you’d have to go about it the roundabout way, tween a CFrameValue, link up a .Changed connection to it and then use the :SetPrimaryPartCFrame method.

you could also utilise the .WorldPivot property of the model and tween it in a similar way that is described above.

although I might be wrong this is what I had to do on multiple occassions

why do a - on the D2 ? i’m lost x)

That was just based on the assumption that D2 should move in the opposite direction compared to D1.

Where would i put the position i want it to go then ?

In terms of tweening models, this is the least cost-effective way on the physics and FPS of doing it, @hollaquetalBRUH you may find that tweening unanchored instances could have a strain on your experience.

Then what the solution i need to do them unanchored with welds to prim and prim anochored to make it worked :face_with_monocle:

The full explanation for my solution is this:

You have a CFrame, and you want to offset it in a specific direction while preserving its rotation. A CFrame has 3 vectors we can use to determine the orientation of the part. These vectors are the LookVector, RightVector and UpVector.

Offsetting a CFrame’s position is easy enough. All we need to do is add a Vector3 to the CFrame, and we get a new CFrame with the same rotation as the original, but with a new position. This Vector3 can be the LookVector, RightVector, UpVector or any arbitrary vector you can think of. See Understanding CFrame for more info.

Let’s assume we want to move the D1 model’s PrimaryPart right 5 studs in its local space. This can be done with

D1.PrimaryPart.CFrame = D1.PrimaryPart.CFrame + D1.PrimaryPart.CFrame.RightVector 
* 5

In practice this means we’re multiplying the RightVector by 5 (resulting in a vector with a length of 5) and adding it to the CFrame.


Useful related links: