#Make an army following a player

18 messages · Page 1 of 1 (latest)

pliant vector
#

Hi guys! I'm working on a first-person RTS game. I've already completed almost everything except for the GUIs. However, I'm currently stuck because I need to figure out how to make an army follow a player. Have you ever played Conquerors Blade? I'd love to implement a similar system but with more advanced features.

The problem I'm facing is that I have no idea how to display the units following the player and add functionalities like "protect the king." For instance, having all long-range units (archers) encircle the player in a perfect formation, and if there are too many archers, they should form multiple circles. After the long-range units, the short-range ones should surround and protect everyone. Do you see what I'm saying?

I've already considered creating numerous patterns like "if the player has 13 archers and 28 guards, execute this pattern." But I think I'll have around six types of units to start with, and if they have 100 soldiers, it's like dealing with 10^9 patterns that I'd have to create manually, which is quite overwhelming.

Do any of you have ideas on how I can approach this? Thanks a lot! <3

rich barn
#

🤣

pliant vector
#

yo what's funny :'(

digital wave
#

No code no help

pliant vector
#

But what do you need? I have no code yet, lol. Maybe I have that. The screen is every part, always following the player. It's like a basic formation template for all units to follow the player.

local runService = game:GetService("RunService")
--local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = game.Players.LocalPlayer
local ArmyPos
local Core

local ArmyPath = workspace:WaitForChild("ArmyPaths")

local FoundArmyPath = false

while not FoundArmyPath do
    wait()
    for _, child in ipairs(ArmyPath:GetChildren()) do
        wait()
        if child:GetAttribute("userId") == player.UserId then
            ArmyPos = child
            Core = ArmyPos.Core
            FoundArmyPath = true
        else
        wait(3)
        end
    end
end



local function FollowThePlayer()
    if player and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
        if Core then
            Core.CFrame = player.Character:FindFirstChild("HumanoidRootPart").CFrame
        end
    end
end

runService.RenderStepped:Connect(FollowThePlayer)
#

rn i'm trying to put make a script to move them all around the player in circle

#

I just have no idea how to do it. It's not like I'm stuck in the code; I just have no idea how to do it.

blissful sorrel
#

Uh

#

Give me a sec

#

I think I got something

#

Could use Humanoid.MoveDirection

#

To get the direction the player is moving in

#

Then make the soldier march at the same walk speed and direction as the player

#

You would have to get them in position first though

#

Which should just be a matter of a MoveTo to the position before starting the follow script

#

So uh that's the idea

last rune
#

Use NPC Pathfinding. Its an easy-to-use and self explanatory plugin. Then make the Pathfinding part an “Attachment” to the Player. Thats literally it. Then clone the NPC to as much as you desire.