Move a set of models to a relative position

  1. What do you want to achieve? I am working on a RTS game and I dont know where to start with this troop movement. I know how to move my troops but lets say the player has 3 troops selected [The grey parts] I want to be able to move to the positions of the black parts, all of this just by knowing the position of they pink part [where the player clicked]

  2. What is the issue? I have no clue how I would begin to solve this issuie. If it helps I am using a raycast to get the pink part position so I have direction values and such.

I just need a way to begin solving this and than I should be able to implement it, thanks in advance!

1 Like

Is this what you might be talking about?
If its the movement itself it may be better to use some form of tweening

The grey parts are not grouped together. In the game they will be rigs so I am using Humanoid:MoveTo()

I just want to know how to move the grey parts to the pink part keeping their formation. [Without grouping the parts]

Do they currently have a humanoid?

The blocks are just a demonstration. I have actual dummies.

Well then ask your question properly, all you asked is to move the parts, not ask us how to move humanoids. We can offer you cframe or tweening with what you asked, what you need is this. Just a simple google search :+1:

image
How do I move all of the dummies to the pink part when keeping them in formation.

  1. Obtain the models and the position of the center that they form
local Models = {workspace.D1, workspace.D2, workspace.D3}

local Center = Vector3.zero
for _, Model in pairs(Models) do
	Center += Model:GetPivot().Position
end
Center /= #Models
  1. Get and store its position relative to the center
local Relative = {}
for _, Model in pairs(Models) do
	Relative[Model] = Model:GetPivot().Position - Center
end
  1. Move them by taking the target point and adding the saved relative position
local NewPosition = workspace.Target.Position
for Model, RelativePosition in pairs(Relative) do
	Model.Humanoid:MoveTo(NewPosition + RelativePosition)
end

Final:

local Models = {workspace.D1, workspace.D2, workspace.D3}

local Center = Vector3.zero
for _, Model in pairs(Models) do
	Center += Model:GetPivot().Position
end
Center /= #Models
print(Center)

local Relative = {}
for _, Model in pairs(Models) do
	Relative[Model] = Model:GetPivot().Position - Center
end

local NewPosition = workspace.Target.Position
for Model, RelativePosition in pairs(Relative) do
	Model.Humanoid:MoveTo(NewPosition + RelativePosition)
end

Shorter code
local Models = {workspace.D1, workspace.D2, workspace.D3}
local NewPosition = workspace.Target.Position

local Center = Vector3.zero
for _, Model in pairs(Models) do
	Center += Model:GetPivot().Position
end
Center /= #Models

for _, Model in pairs(Models) do
	local Relative = Model:GetPivot().Position - Center
	Model.Humanoid:MoveTo(NewPosition + Relative)
end
4 Likes

Thank you for helping, being simple, straight to the point, and understanding! :]

1 Like