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

How do you move multiple parts at the same time?

Asked by 4 years ago

I was wanting to make a Zoo game and I wanted to make the animals feel more alive by making them move around their pen. But I couldn't figure out how I would move multiple parts at the same time. Like a chicken, with lots of different parts and each part moves at the same time, but its not a mesh. Please help me out!

0
If you make the animals a custom character, you can use humanoid:MoveTo(Vector3 Position) and they'll move to whatever positions specified.  can also give the animals animations. royaltoe 5144 — 4y
0
The position you'd move to should be a random position a couple studs away from the character.  you want to get more advanced you can use raycasting to see if the animal is about to run into a wall or somewhere it's not supposed to be / pathfinding to have the pig move up stairs royaltoe 5144 — 4y

2 answers

Log in to vote
0
Answered by
JPT79 92
4 years ago

Ok first up, model all the parts involved, while you can't move models since they don't have a Position value, they do have a PrimaryPart value, So set this PrimaryPart to any part of the animal, although it may be best to choose the main body of the animal. Now that your model has a root part you can move it just like any other part, you'd target it like this

local chicken = script.Parent.PrimaryPart

Of course if your movement script isn't in the model you'll have to change this, but as long as the script is placed in the model it'll work just fine

0
After you did what JP said, you can use model:SetPrimaryPartCFrame(Vector3 Position) to have the animal move to a certain position. This isn't a good practice though since after calling SetPrimaryPartCFrame so many times, the parts positions lose accuracy and end up looking all wonky royaltoe 5144 — 4y
0
TheLastHabanero's idea of using welds to weld everything to a primary part and then moving the primary part is a bit better because it doesn't have any issues issues with accuracy. Since you want to move the animals life like around the pen I think what I said in the comments would work best since you can give the animals animations and it's less code. royaltoe 5144 — 4y
Ad
Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
4 years ago
Edited by royaltoe 4 years ago

There are multiple ways to make different parts move. One of the best ways is using a WeldConstraint. There are multiple plugins where all you have to do is select multiple parts and press a button and you can weld them. Welding puts all the parts together while making them unanchored. If you move one part inside the chicken or cow and they are welded together, the entire chicken or cow will move. I can show you this on Roblox so shoot me a friend request @TheLastHabanero. You can also union all of the parts together. Unioning is not recommended because you can only union objects of the same color.

I hope this helps you!

Best

TheLastHabanero

Edit:

Weld together a model by calling this function:

function weldModel(model)
    --the model needs a primary part to weld all the welds to, 
    --if we don't specify a primary part, then this if statement will warn us in the console.
    if not model.PrimaryPart then 
        warn("Please specify a primary part for the model ".. model.Name) 
    end

    --go through each of the items in the model,
    for _, desc in pairs(model:GetDescendants())do
        --if the item we're looking at is a part or union,
        --weld that part/union to the model's primary part 
        if desc:IsA("BasePart") or desc:IsA("UnionOperation") then
            local weldConstraint = Instance.new("WeldConstraint")
            weldConstraint.Parent = desc
            weldConstraint.Part0 = desc
            weldConstraint.Part1 = model.PrimaryPart
            desc.Anchored = false
        end
    end
end

weldModel(some model)
0
Do I add a WeldConstraint to every part? Krystal_Kyle 47 — 4y
0
yes, i made a function that does all that for you. see edit royaltoe 5144 — 4y
0
Thanks royaltoe! haba_nero 386 — 4y

Answer this question