Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED] Is there an easy way to tween the size of a part but keeping the side at a set position?

I'm making sliding doors, but at the sides of the sliding doors are glass and I don't want it to look as if the glass door is going into the glass and the only way I can think of getting around this is resizing it instead. The only problem is that there's no simple way of doing this, I want to keep the side of the part in one position and I'm not sure if there's some simple logic or maybe even built in functions as there is for CFraming (lerp). Any help is appreciated, thanks for your time!

EDIT: Just so you know, I know it will look unrealistic, but I'm not a realistic person so don't say this isn't how sliding doors work, I KNOW! But again, thanks for any help you can provide.

EDIT (2): This is not a request, I am asking for a method to do something, not for you to fix or do my code for me, but any snippets of code would be a nice extra.

4 comments

0

LUA

0

Oh yeah, good idea, I never though about scripting it...

0

essentially what you want to do is resize the object 1st, and then move it based on its new size (also relative to the position of the "edge" of class it is hitting). not too complicated

0

I was mocking your bio.

1 answer

✓ Accepted answer

Just so you know, this is a request. For it not to be, you need to provide your own attempt at doing this, and we will correct it for you.

This is, however, also a trivial question, so here you go:


You can do this using CFrame and Size changing, which will give accurate collision, but if you already have the code working to have the door itself slide open, and just want to fix the visual, you can use a SpecialMesh with the 'Brick' MeshType.

You set the Scale property to Vector3.new(X, 1, 1), assuming 'X' is the axis the door is 'closing' on. X itself is whatever percentage the door is open.

If, for example, the door takes five seconds to close or open, that would look like this:

door.Mesh.Scale = Vector3.new(t/5, 1, 1)

For opening or this:

door.Mesh.Scale = Vector3.new(1 - t/5, 1, 1)

For closing.

Where t is the elapsed time since the door was 'opened' (or 5 if t > 5).


This will shrink the door evenly, however, which is not desired.

In order to fix this, we need to set the Offset of the Mesh to half of the scaled size of the door:

door.Mesh.Offset = Vector3.new(0.5*door.Size.X*(1 - door.Mesh.Scale.X), 0, 0)

(If this 'closes' in the wrong direction, simply change the 0.5 to -0.5)


I assume you know how to use 't' in the above two snippets, but you might be doing it slower than is possible, and for anyone that doesn't know, here is a full code block with functions to open and close the door with the best smoothness possible from a Script (as opposed to a LocalScript).

local RunService = game:GetService("RunService")

local isOpen = false
local deb = false
local dur = 5

function toggleDoor()
	if deb then return end
	deb = true

	local st = tick()
	while true do
		local t = tick() - st
		if t > dur then t = dur end
		if isOpen then
			door.Mesh.Scale = Vector3.new(1 - t/dur, 1, 1)
		else
			door.Mesh.Scale = Vector3.new(t/dur, 1, 1)
		end
		door.Mesh.Offset = Vector3.new(0.5*door.Size.X*(1- door.Mesh.Scale.X), 0, 0)
		if t >= dur then break end
		RunService.Heartbeat:wait() --This works in Scripts *and* LocalScripts!
	end

	deb = false
	isOpen = not isOpen
end

This discussion is preserved as it was. New answers, comments, and votes are closed.