A door shifts while opening, when it's Parent model is also moving

  1. What do you want to achieve?
    I want to achieve a door to slide open/close

  2. What is the issue?
    The door model is attached to a room, wich moves a lot throught the gameplay. And the door shifts upwards when I try to open/close it while the Parent model is moving down. Video included for your convinience

  3. What solutions have you tried so far?
    I tried looking up solutions on dev forum. Didn’t find anything like my issue. I also tried welding the door to the closest wall using weld or weld contraist, tried grouping the door and that same wall into a model, but nothing helped.

when the room is NOT moving, the script works perfectly fine

The door opening script is following:

-- Define variables
local ProximityPrompt = script.Parent
local Door = ProximityPrompt.Parent.Parent

local isOpen = false

-- Function to move the door
local function moveDoor()
	local openPosition = Door.Position + Vector3.new(0, 0, 3)
	local closePosition = Door.Position + Vector3.new(0, 0, -3)
	
	local tweenService = game:GetService("TweenService")
	local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

	local goal = {}
	if isOpen then
		goal.Position = closePosition
		ProximityPrompt.ActionText = "Open"
	else
		goal.Position = openPosition
		ProximityPrompt.ActionText = "Close"
	end

	local doorTween = tweenService:Create(Door, tweenInfo, goal)
	doorTween:Play()

	isOpen = not isOpen
end

-- Connect the function to the ProximityPrompt
ProximityPrompt.Triggered:Connect(moveDoor)

Here is the video:

Let me guess, you are moving the Anchored room by changing its CFrame? I’m pretty sure it’s because while the room is moving you’re performing the tween from a fixed starting Position to it’s fixed ending Position, but the room is travelling so during the tween the door is staying in it’s tweened location.

I’ve made sliding tween doors on an Unanchored moving model by tweening the C0 or C1 Properties of a Weld (not WeldConstraint) between 2 of the Parts since I couldn’t use an Anchored Part as the door for a normal tweening door. tweening the weld would only change whichever axis you choose, but the weld should remain in place because it’s dependant on the the Position of the Weld Part0 and Part1.

***EDITED

1 Like

Yes, the parent model (room) is Anchored, and is moved using CFrame

Sorry, edited my last post while you were replying to it. See the description of why the Position is changing.

Okay. So. I should:
Weld the door and the closest wall using Weld, Unanchor door, Rewrite the script to make it tween C0 and C1 properties of the weld, right? I just never really worked with Welds before

Change either the C0 or C1, not both.

1 Like

Okay. I will try that. I’ll notify you if it works or not

Okay! This was the fix the whole time! Thank you for your help. I really appreciate it

1 Like

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