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

Making NPC characters chase after another NPC if on different teams?

Asked by 6 years ago

Hello, I'm trying to make my NPC chase after another NPC only if they are on a different team. But I have no idea how to make an NPC chase after an NPC.

For example here how the code should be formatted;

if find another NPC on team blue then chase after them and attack else attack blue team main base.

This is how the script somehow should look like.

But here's the problem;

i don't know how to script the :if find another NPC on team blue then" part and also I don't know how to make NPC's chase after them.

I do know how to make them attack and once I know how to make NPC chase after something I will know how to do the last line as well.

So in the end;

what i'm looking for is

  1. How to find nearest NPC on blue team (StringValue) Forexample; Team: Blue

  2. How to make NPC chase after the enemy.

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You could create two folders in workspace, one called Blue, one called Red and in each npc loop through the other folder and find the closest one to it, to attack it using .magnitude and then use pathfinding to chase it. magnitude, PathFinding , or instead of using folder, set their team and do the rest

local magnitude = (part1.Position - part2.Position).magnitude
print(magnitude)
if magnitude < 50 then
    --code
end
0
I don't get you, please explain with some scripts, I have no idea how to use magnitude and i can't use pathfinding. BlackOrange3343 2676 — 6y
0
Magnitude is the distance between two objects. JoeRaptor 72 — 6y
0
Show me how to use it plz BlackOrange3343 2676 — 6y
0
abnotaddable what does line 1 of your script show? BlackOrange3343 2676 — 6y
View all comments (3 more)
0
shows the studs between the two parts abnotaddable 920 — 6y
0
I need to find nearest enemy not find studs tbh BlackOrange3343 2676 — 6y
0
loop through whatever and then find the one with the lowest magnitude. abnotaddable 920 — 6y
Ad

Answer this question