Need help with moving a part on it's local Vector3 Axis

  1. What do you want to achieve? I want to make a working curtain with tweening.

  2. What is the issue? When I use Vector3 to move the curtain, it moves it on the global axis, not the curtain’s one (local).

  3. What solutions have you tried so far? I have tries using both Vector3.FromNormalId and Vector3.FromAxis (The “FromAxis” one doesn’t support Left/Right movement, only XYZ)

local TS = game:GetService("TweenService")
local C1 = script.Parent.Soul

local deltaSize = 7


local tweeninfo = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local props = {
	Size = C1.Size + Vector3.FromAxis(Enum.Axis.X)*deltaSize , 
	Position = C1.Position + Vector3.FromAxis(Enum.NormalId.Right)*deltaSize/2
}
local propsOpen = {
	Size = C1.Size - Vector3.FromAxis(Enum.Axis.X)/deltaSize ,
	Position = C1.Position - Vector3.FromNormalId(Enum.NormalId.Left)/deltaSize/2
}

local C1Close = TS:Create(C1, tweeninfo, props)
local C1Open = TS:Create(C1, tweeninfo, propsOpen)

open = true
db = false

script.Parent.Soul.ProximityPrompt.Triggered:connect(function()
	if db == false then
		db = true
		if open == false then
			open = nil
			C1Open:Play()
			wait(2)
			open = true
		elseif open == true then
			open = nil
			C1Close:Play()
			wait(2)
			open = false
		end
		db = false
	end
end)

The “Position” is done correctly only when the part’s axis is the same as the global axis. (The “Size” ones work either way, even if the part is not aligned to the global axis)

Starting point:
image

What I want to achieve:
image

What actually happens:

Is there any way my curtain can move left but on its axis and not the global one?

Can’t you just do

local targetCFrame = curtain.CFrame * CFrame.new(-distance, 0, 0)

The Position and Size work together, because I want the curtain to extend from one side. However that is not possible, so I made it extend both ways but simultaneously move it the same studs to the left. That way it gives the effect that one side is always standing there.

Typically if you are going for local manipulations you would use CFrame, because it takes into account rotation. As @bytesleuth said previously, you could write smth like

local targetCFrame = curtain.CFrame * CFrame.new(distance/2, 0, 0)
local targetSize = curtain.Size + CFrame.new(distance, 0, 0)

About the size one it said: Expected Cframe, got Vector3 instead.

local targetSize = curtain.Size + Vector3.new(distance, 0, 0)
1 Like

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