So, I’m trying to make a drawer open when a player touches it, the problem is that I would like the drawer to ALWAYS open forward (even if I rotate it 90 degrees), I put a video showing how it looks when I rotate it to the side, see:
I would like it to always open to the front, but I don’t know how it would do this (I would like to do this in a way that I don’t have to worry about changing the drawer script anymore)
Script:
local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local Collectionbuttons = CollectionService:GetTagged("Buttons")
local Tweens = {
Open = 0.5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0;
Close = 0.5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0;
}
for i,v in pairs(Collectionbuttons) do
v.ClickDetector.MouseClick:Connect(function()
local TweenToPlay = TweenService:Create(v,TweenInfo.new(Tweens.Open),{CFrame = v.CFrame * CFrame.new(Vector3.new(0,0,-4))})
TweenToPlay:Play()
end)
end
Sure, lets say you have a part that you want to push forward regardless of orientation, you’d want it to be done based on the parts actual orientation and work off of that or cframe which is both position and orientation.
Using this, we can take a part like this:
while true do
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, -0.01) -- change to fit direction (ROUGH EXAMPLE)
end
for i,v in pairs(Collectionbuttons) do
v.ClickDetector.MouseClick:Connect(function()
local TweenToPlay = TweenService:Create(v,TweenInfo.new(Tweens.Open),{CFrame = v.CFrame * CFrame.new(v.CFrame.LookVector * 4)})
TweenToPlay:Play()
end)
end
Your best bet will be to use the cframe of the part and multiply with the cframe as you can have future changes for best customization rather then relying that front will always be front.
I’d rather recommend just multiplying with cframe, no need for lookvector or ToWorldSpace.
All you’re doing is multipying the parts cframe with another cframe. easy and simple and customizable.
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,0) -- change the 0,0,0 to any values to any direction you like, if you want it moving forward based on forward lookvector, change last value.