Rotating a part at a pivot point

I wish to create “swaying” trees and I would like to know how I would be able to offset orientation and orientate the branches of the tree at the tip or bottom of the part to make it sway. Preferably I’d like to program the leaves to move individually, my other option is to animate then manually via rigs. Currently my tree parts are anchored and I plan to use TweenService to make the msway.

EDIT: I’m mostly looking for some sort of equation since I’m doing this:

--|| SERVICES ||--
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

--|| VARIABLES ||--
local maxOffset = 10

--|| FUNCTIONS ||--
local function getSwayDirection(Branch)
return Branch.CFrame*CFrame.fromEulerAnglesXYZ(math.random(-maxOffset,maxOffset),0,math.random(-maxOffset,maxOffset))

local newCFrame = getSwayDirection(Branch) -- I'll define it later
TweenService:Create(Branch,, Enum.EasingStyle,Sine), {["CFrame"] = newCFrame}):Play() -- I'll make sure to set Reverse to true as well as if a branch is tween it won't be overlapped


what do you think by sway (because my English)

Take a look at this video, I’m trying to create a “Natural” swaying effect of the leaves with in Roblox.

and what is problem with included code

Right now the orientation of the parts are based off the centre of Position of the BasePart. I’d like to have some sort of “tip” or pivot point to rotate/orientate the leaves.

ok, so add there 2 servos and tween their rotation
edit: or motor6d

The issue is that your entire trees will end up moving together with the trunk, which is even less realistic than static trees. You will have to make a rig with a large number of child branches connected to their parent branches. The further the branching, the higher the sway effect. Motor6Ds you would use would have their C0 located in at the root of the branch. You can apply the offset with C1.

It won’t since each part is individual, I’m looking for a way to rotate the part on a point

Your best bet is to attach each part of the tree through hinge/ballsocket constraints and edit their values to achieve a swaying/bending effect.

To begin with, trees aren’t really “rotating” at their base. They hardly move at their base. Rather, they bend due to the wind. You’d have a lot more luck doing what I mentioned above.

In that case, the easiest way would be by using welds.

I explained the welds in the previous response. The reason why I wouldn’t go for custom CFraming is because the parent branch can also move, so the origin isn’t static.

Branch.Weld.C1 = CFrame.Angles(...)

That is the entire code for one branch using welds.

That would make it highly inefficient as the branches would have to be unanchored.

I guess you’re right. The thing is, the tree swaying effect doesn’t have to be server sided, it can be implemented solely on the client.

True, but multiply that by the number of trees and even a detailed verlet simulation can no longer compare.

1 Like

The basic idea can be found in this link. Specifically the bit about rotating a door as it discusses how to rotate around things that are not the CFrame’s center.

A more general function would be:

local function rotateAroundWorldPoint(currentCF, worldPoint, rotationCF)
	local pivotCF = * (currentCF - currentCF.p)
	local delta = pivotCF:Inverse() * currentCF
	return pivotCF * rotationCF * delta