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]
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!
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
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
Get and store its position relative to the center
local Relative = {}
for _, Model in pairs(Models) do
Relative[Model] = Model:GetPivot().Position - Center
end
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