I’m trying to make a door using tweens, but when I have other unanchored objects near it, they don’t collide with the door.
Here’s the code if it helps.
local ts = game:GetService("TweenService")
local hinge = script.Parent:WaitForChild("Hinge")
local openT = ts:Create(hinge, TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(90), 0)})
local closeT = ts:Create(hinge, TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {CFrame = hinge.CFrame})
local open = false
local opening = false
local remote = script.Parent:WaitForChild("Door"):WaitForChild("Interact")
remote.OnServerEvent:Connect(function(player)
if opening then return end
opening = true
open = not open
if open then
openT:Play()
else
closeT:Play()
end
wait(.5)
opening = false
end)
From my experience, TweenService and physics objects don’t blend well together.
Usually when I code doors that collide with physics objects, I use CFrame:Lerp() to create my own tween, if you will.
Here’s an example of an interpolating function that achieves your goal using CFrame:Lerp():
local rs = game:GetService("RunService")
local hinge = script.Parent.Hinge
local function dosomestuff(cf)
for i = 1, 30 do
hinge.CFrame = hinge.CFrame:Lerp(cf, math.sin(math.rad(i * 3)))
rs.Stepped:Wait()
end
end
Doesn’t seem to work either, might just be an issue with roblox’s physics generally.
Might look into using some kind of constraint of some sort instead
I’ve tested it for myself, and it does seem to work for me. Gonna sound strange, but did you check to make sure that CanCollide is true?
If that still doesn’t work, you can try modifying the function to use welds instead. Welds are usually a good choice for doors who are being stubborn. Changing the function to change a weld C0 / C1 instead of the hinge’s CFrame should do the trick.
Yeah i’ve figured it out - I think it’s based on part size.
CanCollide is on for every object there. That’s the first thing I checked.
Larger parts seem to collide fine, after some testing