I am trying to create a “Plates Of Fate” style of game, I have a script to create Parts and then roughly find the top of the Plate that has been targeted, it then sets the position of the Part to that location (with a little multiplier on Y to make sure a majority of the part is out of the Plate) and uses a WeldConstraint to link the Part to the Plate.
However, when I change the size or position of the Plate, the Part doesn’t stay on top on the surface, it just stays in place and ends up floating in the air or getting merged inside the Plate itself.
Is there any way to fix this? Preferably something that isn’t too intensive at scale.
It’s being scaled with two tweens in a seperate script (The position is just so the plate’s bottom surface remains in the same place and only increases upwards)
local plate = script.Parent
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(7)
local targetSize = Vector3.new(plate.Size.X, plate.Size.Y + 50, plate.Size.Z)
local targetPosition = Vector3.new(plate.Position.X, plate.Position.Y + 25, plate.Position.Z)
local tween1 = tweenService:Create(plate, tweenInfo, {Size = targetSize})
local tween2 = tweenService:Create(plate, tweenInfo, {Position = targetPosition})
tween1:Play()
tween2:Play()
I believe the tween is what’s causing it. If I’m not wrong tweens don’t have any effect on other than the part you’re tweening. Therefor it doesn’t take the welded part in account. You would also have to perform a tween on that. Or scale/move the plate using CFrame while making sure the plate is the basepart for the weldconstraint.
Or no tweening the CFrame would work. Haha idk what I’m thinking!
But changing the size of the part doesn’t make the welded part ‘follow’ with am pretty sure
In that case you would have to recalculate the new Y coordinate for the part according to the plate’s.
You should calculate 1/2 the thickness of the bottom plate (its Y Size/2) and add it to the bottom plate’s Y Position to calculate where the top surface of the bottom Plate is, then calculate 1/2 the size of the plate you are adding and subtract it from the added plate’s Y Position to get the bottom surface of the top plate. This gives you the mating surface position between the 2 Parts.
Then place the top plate at that mating surface position + 1/2 the Y Size of the top plate.
This calculates the Position no matter the Size of the 2 Parts in question.