Thanks for checking out my question!
I was wondering how I can move a model smoothly when using ":SetPrimaryPartCFrame()" on the model.
I'd like to use the TweenService to achieve this effect. Is there maybe a better way to move it than SetPrimaryPartCFrame(), like a value, so I can use the TweenService?
On a side note, can I move it without a primary part? I don't really want to put a middle part inside all the models I'll be using. I know model:MoveTo() exists but this causes it to always be on top, which isn't what I want because it also glitches out when it's at your player.
This is my code:
wait(2);
local previewItem = game.ReplicatedStorage["Wood Crate"]:Clone();
previewItem.Parent = workspace;
local exclusions = {};
for index, descendant in pairs(previewItem:GetDescendants()) do
if descendant.ClassName == "Part" then
descendant.Transparency = 0.5;
descendant.CanCollide = false;
descendant.Anchored = true;
table.insert(exclusions, descendant);
end;
end;
table.foreach(game.Players.LocalPlayer.Character:GetDescendants(), function(i, obj)
if obj.ClassName == "Part" or obj.ClassName == "MeshPart" or obj.ClassName == "Hat" then
table.insert(exclusions, obj);
end
end);
local mouse = game.Players.LocalPlayer:GetMouse();
local camera = game.Workspace.CurrentCamera;
function round(n)
return math.floor(n + .5)
end
mouse.Move:Connect(function()
local unitRay = camera:ScreenPointToRay(mouse.X, mouse.Y);
local ray = Ray.new(unitRay.Origin, unitRay.Direction * 500);
local part, pos = workspace:FindPartOnRayWithIgnoreList(ray, exclusions);
if part then
previewItem:SetPrimaryPartCFrame(CFrame.new(Vector3.new(round(pos.X), round(pos.Y + (previewItem:GetExtentsSize().Y / 2)), round(pos.Z))));
end;
end);
If any part of the code can be more efficient, like the exclusions, please let me know too :)
tldr; I want a model to follow the mouse on a grid with raycasting, smoothly, and preferrably without setting the PrimaryPart. How?

1 comment
u dont. set primary part, anchor it, unanchor every other part, weld it to primary part, tween.