I’m looking to use the tween service to move a rather large fully rigged model to multiple waypoints. I am currently able to get a part in the model to move to a waypoint. However, I can not get the entire model to move. I have used a tutorial from the YouTubes (SimTek Game Development) on moving models, so I don’t take credit for the code. I have modified it slightly and have either messed up the code or it just doesn’t work for this particular application. I get no response in game and no issues come up in the output, all parts in the model are unanchored as well.
I suspect the issue is from the Value for the CFrame position under the tween service create. I have highlighted where I think the issue is.
Before moving the model, make sure everything you want to move(every BasePart) is parented inside the model and it’s also Anchored. Physics based anchoring using welds and such may be the issue.
CFrames have a constructor that uses only a Vector3 position, so the OP’s code is correct.
CFrame.new ( Vector3 pos )
Returns a CFrame with no rotation with the position of the provided Vector3.
To move an entire model you need to use CFrame and constraints. Using Position messes with the C0 and C1 of the constraints, so the CFrame property should be used instead of the Position property.
To move an entire model, you’ll need to do a few things:
Pick a central part. In your case, it’s the Model.RootPart
Anchor only the central part (optional, you can also leave everything unanchored)
Make sure the entire model is welded together. This keeps all the parts attached to the central part.
Then all you need to do is tween the CFrame of the central part. (Using Position and Rotation will adjust the C0 and C1 of the constraints, so CFrame is the correct property.) Here is some example code:
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(30, Enum.EasingStyle.Quad, Enum.EasingStyle.Out, 0, false, 0)
local function moveModel(model, wayPoint)
-- Can also switch to wayPoint.CFrame to keep the goal rotation of the wayPoint part/attachment
local goal = {CFrame = CFrame.new(wayPoint.Position)}
local tween = TweenService:Create(model, info, goal)
model.PrimaryPart.Anchored = true
tween:Play()
local connection
connection = tween.Completed:Connect(function()
model.PrimaryPart.Anchored = false
connection:Disconnect()
tween:Destroy()
end)
end
I have parented everything to the model and anchored the root part. But you do bring up another concern, I am using motor6d attachments from moon animator easy weld plugin. Do you think this maybe causing part of the issue? I intend for the model to be animated as it moves almost similar to an NPC
I will try to give this a shot. Right now I have a moving root part, but the model does not move with it. So, I’m hoping it is an attachment issue. Here’s an idea of what I’m working with for reference. Using motor6d’s for attachments from the moon animator easy weld.
I know that they use a Vector3 position and I do not know if this is a glitch but when you put just the Position value, it doesn’t work for CFrame.new(). I’ve tried doing it before which is why I know that.
I believe the problem is either than your motor6s don’t connect to your HumanoidRootPart or something to do with using Welds instead of WeldConstraints. I’d go through your Motor6s and make sure they connect to the HumanoidRootPart at some point.
This did work. I will apply the animation when I have a chance and see if the animation is able to run. Thanks!
Animation seems to run. Awesome thanks!