Hi, so I am attempting to tween a model using vector3 for a target position (end position of the tween) and I wish to get the position of the model and add a vector3 value to it to get my desired position. If possible, I would like to get the position of the model and add those vector3 values, but I am also willing to try other methods. I have searched for other topics but I wasn’t able to find anything other than posts related to manually moving models. I’m sorry to be asking so many questions, but I am being introduced to a lot of things I’ve never worked with before and I’m trying to piece everything together with things I find off other posts. Thanks!
right now theres no way to direecrly tween a model’s position
but there are several workarounds:
create a CFrameValue/Vector3Value and tween the value to the correct position
Then after that hook up a heartbeat or a loop of some kind, and use :moveto() or :pivotto() on the model based on the cframe/vector3 value.
just make sure you disconnect/end the loop after the tween is finished or it could be laggy cuz your looping the positino for no reasons
the second option is tweening every part in the model which is kinda laggy
the third option is welding all parts to a single part which is anchored then tweening that parts position which makes all others folow it cuz its welded. This is good but it can be destroyed by explosions
there are probably several other work aroudns but thats what I can think of
This is unrelated to your problem, but:
You generally shouldn’t name your variables after globals. This can lead to future confusion if you were to revisit this later down the line
A way to do this to create a part and set it as the model's primary part
, then weld every part of the model to it, and then tween the primary.
for i,v in next, model:GetDescendants() do
local weld = Instance.new("WeldConstraint")
weld.Part0 = v
weld.Part1 = model.PrimaryPart
weld.Parent = v
end
Its Possible as I managed to do it without welding, but I’m not sure about it being unanchored, or with rotations:
function lerp(a,b,t)
return a + (b - a) * t -- Lerp Formula
end
function lerpModel(model: Model, endGoal, timePos)
local fixedtime = math.clamp(timePos or 1, 0, 1) -- sets a Fixed number betwen 0 and 1
local pos = model:GetPivot().Position -- This is just a Position Example, not going to bother lerping a CFrame as it can be a bit complicated thing to do
local newpos = lerp(pos, endGoal, fixedtime) -- Interpolated Position
model:PivotTo(CFrame.new(newpos)) -- sets new Position
end
Yea, it should work.
limittt
I’m assuming I should also define the primary part in the tween function, replacing the model with it, right?
If you want to tween a model u should follow this:
Introduction to Tweening Models - Resources / Community Tutorials - DevForum | Roblox
Would it be okay to manually wield the parts instead? I know it is not the most efficient process, but I feel more comfortable doing it that way than through a script. Would I simply define the primary part after and tween that instead? Would that move the entire model?
Yes, and yes. It’s fine if you rather manually weld or not, so long as it works.