Page 1 of 1

Getting Spawned Units to Follow the Spawner [Solved]

Posted: Thu Oct 01, 2009 9:42 pm
by Sky_216
**This is being used for DS as a replacement for the overpowered mobile command post. archer01 made most of the code.**

The idea is it spawns a squad of security droids that follow the spawner (tactical droid, can be human or ai) around. They spawn fine, they work fine...except I can't get them to follow the tactical droid around (just sit still so clearly the code is messed up somewhere). Anyone with experience in this sort of thing able to help?

Code:
Hidden/Spoiler:
[code]OnCharacterDispenseControllableTeam(
function(character,controlled)
if GetEntityClass(controlled) == GetEntityClassPtr(TroopSpawnerWeapon) then
local SupportTeam = 3 --Team the new spawned character is in (change this)
local teamSize = GetTeamSize(SupportTeam)
for i = 0, teamSize-1 do
local characterIndex = GetTeamMember(SupportTeam, i)
local charUnit = GetCharacterUnit(characterIndex)
local leaderIndex = GetEntityPtr(character)
if not charUnit then
local destination = GetEntityMatrix(GetCharacterUnit(character))
SpawnCharacter(characterIndex,destination)
ClearAIGoals(3)
AddAIGoal(3, "Follow", 100, leaderIndex)
end
end
end
end,
CIS --User team (change this)
)[/code][/size]

Re: Getting spawned units to follow the Spawner

Posted: Thu Oct 01, 2009 10:03 pm
by [RDH]Zerted
Put the AI goal's target on the character's unit and move the ClearAIGoal and AddAIGoal lines above the loop. One adds AI goals for each team, not for each team member.

Re: Getting spawned units to follow the Spawner

Posted: Thu Oct 01, 2009 10:53 pm
by Sky_216
Thanks Zerted, worked perfectly :)