Problem with part not orientating accordingly

Hi hi,

I’ve been trying to create some lively foliage, however I’ve stumbled into a problem with how the foliage orientates. The foliage is supposed to rotate to move out of the way, as seen below:

(The blue arrow represents the top normal of the foliage. The green arrow represents the forward normal of the character; the Humanoid’s MoveDirection)

(Let’s just imagine the grey part is a bush, flower, fern, or whatever you’d like)

I currently have this outcome:

The code to manipulate the cframe currently looks like this:

local function getFoliageDirection(x0: number, z0: number)
	return CFrame.Angles(x0, 0, z0)
end
	
local function updateFoliageCFrame(foliage: BasePart, moveDirection: Vector3)
	-- the move direction is the Humanoid's MoveDirection property
	local x0 = math.rad(moveDirection.X * FOLIAGE_ROTATION_MULTIPLIER) -- FOLIAGE_ROTATION_MULTIPLIER = 45
	local z0 = math.rad(moveDirection.Z * FOLIAGE_ROTATION_MULTIPLIER)
		
	local originalCFrame = foliage:GetAttribute("OriginalCFrame") -- this is the base cframe of the foliage
	local foliageDirection = getFoliageDirection(x0, z0) -- this is the offset cframe
		
	tweenService:Create(foliage.PivotValue, FOLIAGE_BEGIN_TWEEN_INFO, { Value = originalCFrame * foliageDirection }):Play()
end

Any hints or points in the right direction would be greatly appreciated. Thank you :slight_smile: