How to follow Player as a Group?

  • December 28, 2016 at 18:42 #17338
    Elias Lessa
    Participant

    Hi i’m trying to figure out, with no luck, how to set a group of 4 AI Units to follow the player as a group, there is some tutorials on youtube, but my problem is that my player is 3rd person character controlled by the user. How do i set the units as a group whitout selecting them ? And how do i make them as group follow the Player character?

    Also at first they will follow him as a disorganized group but in the future i intend to have them following the player in a formation, like shield wall or a triangle.

    Att. Elias

    December 28, 2016 at 22:24 #17340
    Elias Lessa
    Participant

    Ok, the grouping and formation part is ok, now only the follow left, i’ve tried to put the MoveTo(Player) on the Update Method but the Units stand still recalculating the path every frame i guess.

    December 28, 2016 at 22:52 #17342
    Elias Lessa
    Participant

    Thought it was ok, out of nowhere i started to receive the following message:

    NullReferenceException: Object reference not set to an instance of an object
    Apex.Units.TransientGroup`1[T].PrepareForAction () (at Assets/Apex/Apex Path/Scripts/Units/TransientGroup.cs:399)

    Current code:

    • This reply was modified 9 months, 3 weeks ago by Elias Lessa.
    December 28, 2016 at 23:04 #17345
    Elias Lessa
    Participant

    Ok, back again on track, it seems that Unity decided to call the Initialize of the script above before the Start of the PlayerUnit wich assing the unitFacade with GetUnitFacade();

    Now, only missing a way to follow the player.

    December 29, 2016 at 16:00 #17360
    Geminior
    Keymaster

    You are right calling MoveTo each frame will not work as the path finder is async and decoupled from steering and hence it is very likely that a path will never be returned in time to be used that frame.

    Please have a look at this post.

    December 29, 2016 at 18:36 #17380
    Elias Lessa
    Participant

    Thanks! it worked.

You must be logged in to reply to this topic.