You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Im looking for a system that makes multiple object to not push each other while moving to a single target. -
What is the issue? Include screenshots / videos if possible!
I’ve been working on a RTS game, based on other games like Medieval RTS and Normal Real Time Strategy Game, these two games have a group movement system, this means that multiple units will be able to move at the same time without selecting them individually. The issue is that I couldn’t find any way to individually modify the target position from every selected unit based on the individual unit current position.*Note: A “Target” is basically where the player clicks (This works using
Mouse.Hit
)
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried many different ways, but I couldn’t find any solution to this.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
My code:
MoveUnitEvent.OnServerEvent:Connect(function(player,hitpos,selected)
local loop = true
local vector = Vector3.new(selected.Parent.HumanoidRootPart.Position.X/selected.Parent.HumanoidRootPart.Position.X*selected.Parent.HumanoidRootPart.Position.X/distance,0,selected.Parent.HumanoidRootPart.Position.Z/selected.Parent.HumanoidRootPart.Position.Z*selected.Parent.HumanoidRootPart.Position.Z/distance)
local FixedHitpos = hitpos + vector -- IMPORTANT: Here is the issue
print(vector)
positions[selected] = {FixedHitpos}
selected.Parent.HumanoidRootPart.BodyGyro.CFrame = CFrame.lookAt(selected.Parent.HumanoidRootPart.Position,hitpos)
game.ReplicatedStorage.RemoteEvents.CreateBeam:FireClient(player,positions[selected][1],selected.Parent,false)
--// Start a loop that constantly changes PlaneVelocity according to the position of Unit
while loop and selected.Parent and positions[selected][1] == FixedHitpos do
selected.Parent.HumanoidRootPart.Vel.PlaneVelocity = Vector2.new(FixedHitpos.X - selected.Parent.HumanoidRootPart.Position.X,FixedHitpos.Z - selected.Parent.HumanoidRootPart.Position.Z).Unit * selected.Parent.Settings.Stats.Speed.Value
if (selected.Parent.HumanoidRootPart.Position - positions[selected][1]).Magnitude > 1 and selected.Parent and positions[selected][1] == FixedHitpos then
selected:SetAttribute("repeating",true)
else
loop = false
selected:SetAttribute("repeating",false)
end
task.wait(.1)
if selected.Parent then
if selected:GetAttribute("repeating") == false then
print("stopped")
selected.Parent.HumanoidRootPart.Vel.PlaneVelocity = Vector2.new(0,0)
game.ReplicatedStorage.RemoteEvents.CreateBeam:FireClient(player,positions[selected][1],selected.Parent,true)
end
end
end
end)
If I wasn’t clear, feel free to reply!
(This is my very first topic)