Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you move a model using the TweenService?

Asked by
Nowaha 459 Moderation Voter
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:

01wait(2);
02 
03local previewItem = game.ReplicatedStorage["Wood Crate"]:Clone();
04previewItem.Parent = workspace;
05 
06local exclusions = {};
07 
08for 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);
14    end;
15end;
View all 39 lines...

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?

0
u dont. set primary part, anchor it, unanchor every other part, weld it to primary part, tween. Elixcore 1337 — 5y

1 answer

Log in to vote
0
Answered by
U_srname 152
5 years ago

Here is a way I found out recently. First, I'll give you the code then explain:

1-- Replace line 37 with this
2 
3previewItem:TranslateBy(Vector3.new(round(pos.X), round(pos.Y + (previewItem:GetExtentsSize().Y / 2)), round(pos.Z)))

First, you might need to change your math since you aren't using SetPrimaryPartCFrame, I haven't checked that.

So, recently I was looked at the Scripting Helpers Tip of the Day and found this. I did more research and found I was actually looking for this a few weeks ago.

As explained by the Roblox Developer site:

Shifts a Model by the given Vector3 offset, preserving the Model's orientation. If another BasePart or Terrain already exists at the new position then the Model will overlap said object.

The only issue with this might be that it translates in world space.

Hope I helped!

0
It isn't possible using tween service, but this should give the same effect U_srname 152 — 5y
0
TranslateBy shifts by an offset, but I'm trying to move it to a specific location. Nowaha 459 — 5y
Ad

Answer this question