Cframing door orientation not working

I am trying to Move these two doors with Cframes with the use of CollectionService, I want them to slide open in the direction the red arrow is facing in the photo below:

When doing so however, only the one with the orientation of 0,0,0 (the orange one) appears to work as intended:

Here is the code that updates the Doors:

	ClickDetector.MouseClick:Connect(function(player) ClickDetector.MaxActivationDistance = 0
		
		if Configuration.KeyCard.Value then
			if player.Team == game.Teams.testing then
				return
			end
		end
		
		
		
		Sounds.door_open:Play()
		TweenService:Create(CFrameValue, TweenInfo.new(1, EasingStyle, EasingDirection), {Value = CFrame.new(DoorLoaderModel:GetPivot().Position + Vector3.new(0,0,-4))}):Play()	
		task.wait(1)
		
		task.wait(2)
		Sounds.alert:Play()
		task.wait(Sounds.alert.TimeLength + 1)
		
		
		Sounds.door_close:Play()
		TweenService:Create(CFrameValue, TweenInfo.new(1, EasingStyle, EasingDirection), {Value = CFrame.new(DoorLoaderModel:GetPivot().Position + Vector3.new(0,0,4))}):Play()
		task.wait(1)
		
		
	ClickDetector.MaxActivationDistance = MaxActivationDistance end)
	
	CFrameValue.Changed:Connect(function(val)
		DoorLoaderModel:PivotTo(val)
	end)

scrap what i said, i was confused

it looks like the tween forces the door to face like the orange one does,

the issue lies somewhere here

I think you’re rotating it along the wrong axis.

Instead of Vector3.new(0, 0, -4)

Do Vector3.new(0, -4, 0) or Vector3.new(-4, 0, 0)

1 Like

Simply because you’re always moving it along the Z axis, so according to your video, the orange door must be along the z - axis hence the reason it works, to fix this you can find the left vector of your door and multiply it by 4. (You might have to change this depending on how you set it up if it doens’t work)

Here is the code that implements this:

ClickDetector.MouseClick:Connect(function(player) ClickDetector.MaxActivationDistance = 0
		
		if Configuration.KeyCard.Value then
			if player.Team == game.Teams.testing then
				return
			end
		end
		
		
		
		Sounds.door_open:Play()
		TweenService:Create(CFrameValue, TweenInfo.new(1, EasingStyle, EasingDirection), {Value = CFrame.new(DoorLoaderModel:GetPivot().Position + DoorLoaderModel:GetPivot().LeftVector*4)}):Play()	
		task.wait(1)
		
		task.wait(2)
		Sounds.alert:Play()
		task.wait(Sounds.alert.TimeLength + 1)
		
		
		Sounds.door_close:Play()
		TweenService:Create(CFrameValue, TweenInfo.new(1, EasingStyle, EasingDirection), {Value = CFrame.new(DoorLoaderModel:GetPivot().Position + DoorLoaderModel:GetPivot().LeftVector*-4)}):Play()
		task.wait(1)
		
		
	ClickDetector.MaxActivationDistance = MaxActivationDistance end)
	
	CFrameValue.Changed:Connect(function(val)
		DoorLoaderModel:PivotTo(val)
	end)

image

That’s my bad, I meant right vectors:
ClickDetector.MouseClick:Connect(function(player) ClickDetector.MaxActivationDistance = 0

	if Configuration.KeyCard.Value then
		if player.Team == game.Teams.testing then
			return
		end
	end
	
	
	
	Sounds.door_open:Play()
	TweenService:Create(CFrameValue, TweenInfo.new(1, EasingStyle, EasingDirection), {Value = CFrame.new(DoorLoaderModel:GetPivot().Position + DoorLoaderModel:GetPivot().RightVector*-4)}):Play()	
	task.wait(1)
	
	task.wait(2)
	Sounds.alert:Play()
	task.wait(Sounds.alert.TimeLength + 1)
	
	
	Sounds.door_close:Play()
	TweenService:Create(CFrameValue, TweenInfo.new(1, EasingStyle, EasingDirection), {Value = CFrame.new(DoorLoaderModel:GetPivot().Position + DoorLoaderModel:GetPivot().RightVector*4)}):Play()
	task.wait(1)
	
	
ClickDetector.MaxActivationDistance = MaxActivationDistance end)

CFrameValue.Changed:Connect(function(val)
	DoorLoaderModel:PivotTo(val)
end)

Try changing the RightVector parts to LookVector


I think I need to change something on the actual LookAt part of the cframe being used in the tween, but i’m not sure how to go about that either

You need to set the cframe to the cframe it has including the rotation and then add the look vector. You know how to do that?

I’ve tried, but have been unsuccessful

You’ve got to assign a part in which you can look at it’s LookVector to then apply a position based on that.

ClickDetector.MouseClick:Connect(function(player) ClickDetector.MaxActivationDistance = 0
		
		if Configuration.KeyCard.Value then
			if player.Team == game.Teams.testing then
				return
			end
		end
		
		
		
		Sounds.door_open:Play()
		TweenService:Create(CFrameValue, TweenInfo.new(1, EasingStyle, EasingDirection), {Value = DoorLoaderModel:GetPivot()+DoorLoaderModel:GetPivot().LookVector*-4}):Play()	
		task.wait(1)
		
		task.wait(2)
		Sounds.alert:Play()
		task.wait(Sounds.alert.TimeLength + 1)
		
		
		Sounds.door_close:Play()
		TweenService:Create(CFrameValue, TweenInfo.new(1, EasingStyle, EasingDirection), {Value = DoorLoaderModel:GetPivot()+DoorLoaderModel:GetPivot().LookVector*4}):Play()
		task.wait(1)
		
		
	ClickDetector.MaxActivationDistance = MaxActivationDistance end)
	
	CFrameValue.Changed:Connect(function(val)
		DoorLoaderModel:PivotTo(val)
	end)
end
1 Like

fixed! thanks dude!

1 Like

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