# Can tweenservice rotate a wall on its edge without weldconstraint?

I want to tween-rotate a wall on its edge (falling over), instead of default centered rotation.

When I attempt it, it shifts sideways into place, instead of rotating around its corner.

I construct the offset cframe between pivot point and wall, as
pivot_cf:inverse() * wall_cf.
I am basing it on oft-cited “CFrame Math Operations”,
section ‘Rotate a Door around hinge’.

Strange is, it looks like the start and end frames are OK (?)
when doing the animation,
but that it just LERPs incorrectly between them.

I’m confused whether it is directly possible with tweens,
or if it instead requires I attach the wall separately to a hinge,
and then rotate the hinge directly.
That is probably what my ‘real’ question is:
Is this possible directly on the wall, with CFrame manipulation and tweens,
or do I have to attach the wall to a ‘real’ hinge and rotate that?

``````local tweens = game:GetService("TweenService")
local wall:Part = workspace.wall

local function tilt()
local ti = TweenInfo.new(24,Enum.EasingStyle.Linear,
Enum.EasingDirection.Out)
local wall_cf = wall.CFrame
local size:Vector3 = wall.Size
print('size:', size)

local pivot_delta:Vector3 = Vector3.new(0.5*size.X, 0.5*size.Y, 0)
local pivot_pos:Vector3 = wall.Position-pivot_delta
print('pivot_pos:', pivot_pos)

local pivot_cf = CFrame.new(pivot_pos)

local offset_cf:CFrame = pivot_cf:inverse() * wall_cf
print('offset_cf:', offset_cf.Position)

local down:CFrame = pivot_cf * CFrame.Angles(0,0,math.rad(90)) * offset_cf
local goal = {CFrame = down}
local tween = tweens:Create(wall, ti, goal)
tween:Play()
end

tilt()
``````

As I continue working on this, I’ll share what (I think) I 've learned so far.

First, I’m still not sure what I was trying to achieve is directly possible with CFrames.
(the reason I was asking here, is to learn the ‘limits’ of working with CFrames).
Instead, I can tell which approaches work and are normally used.
This also highlights any (mis)understandings underpinning how roblox engine works.

A primary thing to understand about the roblox 3d workspace, is that unlike other 3d engines, nested hierarchies of models and parts DO NOT MOVE/TRANSLATE TOGETHER by default.
In other 3d engines, your model hierarchy will typically consist of nested transforms that act on each other in sequence. E.g. your carriership moves, the airplanes on its deck move with it, the retractable wings on the plane move relatively with the airplane, and the flappers on the wings move relative to the wing.
None of this ‘nested connected transforms’ happen anywhere in Roblox, unless you have explicitly set up it should happen!
The way this is handled is with CONSTRAINTS. They have happily many names and variants in Roblox: Welds, Snaps, Motor6Ds.

I was getting a bit ahead of myself there. As already mentioned, I have not been able to hinge-rotate a wall-part directly through its own CFrame.
What I CAN get to work though, is of course using a proper hinge.
So if you create a sort of pivot ‘pole-to-turn-around’ hinge part,
and a wall/door edge-aligned with this pivot-hinge-part,
you of course CAN get the wall/door to turn correctly on its edge around the hinge,
by rotating the HINGE.
But as already explained, for this to work, requires the hinge and the door-wall to be glued together. Gluing together, you can do with a WeldConstraint or Weld (weld is an earlier incarnation of weldconstraint).
You do not have to worry about the hinge being visible in your 3d world, because it still works if you make it invisible and/or incredibly tiny.
If you use the hinge-method, all/most of the CFrame questions vaporize into thin air.
This is because, when you turn around the hinge, your CFrame transformation can be a simple 90-degree rotation in place.

IE, your rotation code boils down to.

local goal_down = {CFrame = pivot_cf * CFrame.Angles(0,0,math.rad(90))}
local tween = tweens:Create(pivot, ti, goal_down)

The go-to community guide for explaining these aspects to newbies, is
“introduction-to-tweening-models”

However, my question still stands:
I want to understand what is possible with CFrame,
especially in relation to tweens/tween-service.

I am pretty sure what I was trying to do, is possible
with CFrames, WITHOUT TWEENS, basically
because roblox’ own tutorial illustrates it.
So, I suspect the truth is ‘yes, possible with cframes,
but not possible with the limitations of how tweens work’.

On the other hand, I suspect it might be possible anyway,
by using the ‘pivotXXX’ stuff that Parts have.

A further thing:
Roblox Studio does allow you to configure a pivot point for your models (e.g. so your wall or door can rotate around its edge or corner).
However, even though you can access these from lua scripts(*),
you cannot affect scripted animations through them. In particular, rotating your parts in a script, will happily ignore this pivot field. It seems to only engage when working manually interactively in roblox studio :-/

There is a footnote on this roblox page noting they can’t be used in scripts:

(" Changing this property will not move or rotate the object. ")

(*) rblxStudio IDE shows plenty of ‘interaction properties’, that have no accessible counter-parts in lua scripts.

Hmm, actually you CAN use it in scripts I think, with the lua method ‘PivotTo()’,
the shame is that it cannot be addressed by tweens.