How do i tween CFrame without changing the rotation?

How do i tween CFrame without changing the rotation of the block i am tweening?

Also please dont type messages like “Use Position”, i cant use it.

1 Like

CFrames and Vectors can be used in math operations.

Changing position along the world axis:

{CFrame = block.CFrame + Vector3.new(0,10,0)} -- 10 studs upwards (world space)

Changing position along the block axis:

{CFrame = block.CFrame * CFrame.new(0,0,-10)} -- 10 studs forwards (object space)

(The existing rotated CFrame is taken and the transformation to it is applied with another CFrame.)

Of course, for the latter, although multiplying CFrames is very straightforward, we can also take LookVector, UpVector, or RightVector to apply the change in the form of a vector, for instance:

{CFrame = b.CFrame + b.CFrame.LookVector * 10} -- 10 studs forwards (object space)
4 Likes

I still dont understand how am i supposted to tween CFrame without changing rotation

Can you explain again?

1 Like

The code lines from the previous reply are wrapped in braces as properties to be tweened, for instance:

local tween = TweenService:Create(
    block, TweenInfo.new(5), {CFrame = block.CFrame * CFrame.new(0,0,-10)}
)

image

The blue block represents red block’s CFrame before tweening along the part’s local axis. Orientation is retained.

local tween = TweenService:Create(
    block, TweenInfo.new(5), {CFrame = block.CFrame + Vector3.new(0,0,-10)}
)

image

In the picture 2, the red part retained the original rotation, while it was moved by -10 studs along the global z-axis (blue line on the view selection box).

One doesn’t have to understand the math behind CFrames to apply transformations, though it certainly helps, and becomes a necessity for more complex ones. Here’s a nice read on working with matrices.

3 Likes

you can get CFrame rotation and just multiply inversed rotation to your CFrame

local c = CFrame.new(0, 1e1, 0)*CFrame.Angles(0, math.rad(90), 0) 
game:GetService("TweenService"):Create(instnace, tweenInfo, {CFrame = c*c.Rotation:Inverse()}):Play()
1 Like

I got it, but im setting CFrame.

I actually made another post
explaining, but i still dont get it.

Im setting CFrame

Actually just found this tweet.

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