How do you move a model using the TweenService?
Asked by
5 years ago Edited 5 years ago
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:
03 | local previewItem = game.ReplicatedStorage [ "Wood Crate" ] :Clone(); |
04 | previewItem.Parent = workspace; |
08 | for index, descendant in pairs (previewItem:GetDescendants()) do |
09 | if descendant.ClassName = = "Part" then |
10 | descendant.Transparency = 0.5 ; |
11 | descendant.CanCollide = false ; |
12 | descendant.Anchored = true ; |
13 | table.insert(exclusions, descendant); |
17 | table.foreach(game.Players.LocalPlayer.Character:GetDescendants(), function (i, obj) |
18 | if obj.ClassName = = "Part" or obj.ClassName = = "MeshPart" or obj.ClassName = = "Hat" then |
19 | table.insert(exclusions, obj); |
23 | local mouse = game.Players.LocalPlayer:GetMouse(); |
24 | local camera = game.Workspace.CurrentCamera; |
27 | return math.floor(n + . 5 ) |
30 | mouse.Move:Connect( function () |
31 | local unitRay = camera:ScreenPointToRay(mouse.X, mouse.Y); |
32 | local ray = Ray.new(unitRay.Origin, unitRay.Direction * 500 ); |
34 | local part, pos = workspace:FindPartOnRayWithIgnoreList(ray, exclusions); |
37 | previewItem:SetPrimaryPartCFrame(CFrame.new(Vector 3. new(round(pos.X), round(pos.Y + (previewItem:GetExtentsSize().Y / 2 )), round(pos.Z)))); |
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?