RTS like Starcraft II

  • March 15, 2018 at 19:59 #22890
    DeeLucky
    Participant

    Hey.

    I’ve just bought the Apex Path and Apex Steering. I want to have pathfinding similiar(or the same) as in Starcraft II. Can anyone point me how to achieve that?

    https://gyazo.com/932ea94b3a78db2a95d8266e61a3d240

    As you can see the agents take into account their ally agents which are currently attacking enemy while searching for another path.

    Thanks!

    March 16, 2018 at 10:54 #22897
    Rami
    Keymaster

    Hi Deelucky,

    Thanks for posting.

    You should browse through the example scenes in Apex Path and Apex Steer to see what the products offer out-of-the-box. For an example, Apex Steer provides a ‘flocking’ behaviour similar to how units in StarCraft will resolve their final destination in congested space.

    If you find that you cannot achieve the desired behaviour with the provided components, you can relatively easily write your own Steering component to get the behaviour you want.

    March 16, 2018 at 11:01 #22899
    DeeLucky
    Participant

    Hey Rami,

    Thanks for the answering my question.
    I’ve got my hands on the components that were offered in examples already. Right now, I’ve achieved something like this:
    https://gyazo.com/a1e22680bdddc6213690ef65af2f3554

    I was wondering how to achieve the effect of units to stop before target and other ally units to avoid the stopped units. Can you point me some direction?

    Thanks

    March 19, 2018 at 14:09 #22922
    Rami
    Keymaster

    Units will by default move to their intended destination. The way Apex Steer handles the situation with crowds is, like units in Starcraft, the stationary units will yield their position (move outward) to make room for incoming (still in movement) units.

    If you want units to stop before the target, you can either start whipping up custom steering components for this use-case, or you could attempt to account for this when issuing the path request. Instead of asking the unit to move to the exact destination, it needs to stop X units before-hand. For crowds, this can be facilitated through a custom formation (IFormation), at least to some extent.

    Units will not by default avoid stationary units. One ‘hack’ that you can use is have units become/place dynamic obstacles (Apex Advanced Dynamic Obstacles) at their location when stationary. This will trigger repaths and vector fields that avoid the now blocked position. This method will actually also work, at least to some extent, for getting units to stop before a target, as the target’s position will simply read as blocked. You may need to search for nearby unblocked cells however, when issuing the path request (or use the relevant setting on the PathOptions component).

    March 22, 2018 at 16:29 #22970
    DeeLucky
    Participant

    Thanks again for essential informations.

    I’ve started to implement your approach, although I’ve came across a little problem – is there any way to make vector field instantly?

    Right now, it seems it has a delay of about 0.1s, which in fast paced games is forever.
    https://gyazo.com/f158b286a794540372fa2912b8c74adb

    March 22, 2018 at 17:26 #22972
    Rami
    Keymaster

    Vector fields are made ‘instantly’ – in the sense that they are genereted in one frame.

    The time it takes to generate depends on the size of the vector field, the type of it and the complexity of the grid, i.e. the size of the grid and the cell size.

    If you have to reduce the time it takes you will need to experiment with how small a vector field and how simple a grid you can live with for your use-cases.

    March 22, 2018 at 18:43 #22974
    DeeLucky
    Participant

    ohh! So that’s how it is!

    Great, thanks to you, I managed to achieve instant group movement.
    The next question is how to obtain callback when the group have ended movement?
    I’ve watched films about messaging module and I’m trying to use it but somehow it just doesn’t make sense sometimes. For example – my units implement IHandleMessage<UnitNavigationEventMessage> interface and their Handle method looks like this:

    https://gyazo.com/c0b29747439419b4949fdb09650246ce

    So the first think as you can see I’m managing the UnitNavigationEventMessage.Event.None, because it really is often when the unit is ending it’s path. Is there something I do not know that I need to set up in apex settings?

    The second thing I do not know how to manage is how to handle messages when it comes to groups?

    • This reply was modified 3 months ago by DeeLucky.
    March 23, 2018 at 10:37 #22977
    Rami
    Keymaster

    So the first think as you can see I’m managing the UnitNavigationEventMessage.Event.None, because it really is often when the unit is ending it’s path. Is there something I do not know that I need to set up in apex settings?

    When are you getting ‘None’ events? I cannot reproduce a situation where I get one of those. Are you using any custom components that announce unit navigation events? If you poll the state of the last navigation event on a unit it may be None at times when there is no navigation event, so to speak, but your HandleMessage method should not get a None event code message.

    The second thing I do not know how to manage is how to handle messages when it comes to groups?

    Groups actually also announce UnitNavigationEventMessages. If you need a reference to the group from the message you can get it through the entity’s unit facade, like so:

    message.entity.GetUnitFacade().transientGroup

    March 23, 2018 at 14:26 #22979
    DeeLucky
    Participant

    Well, I’m getting this None event pretty often when unit is at it’s destination. None of my scripts are announcing the navigation events. But all my scripts are inheriting from your scripts, for example I’m having my custom CultSteerableUnit which inherits from SteerableUnitComponent. I do not know if that matters.

    Here’s an example of the getting the event None:
    https://gyazo.com/8755daf98ebed64d3f44ec09d439f965

    March 23, 2018 at 15:15 #22981
    DeeLucky
    Participant

    Actually, I’ve noticed that this message event appears only at the beginning of the game – after a while, it starts to send correct event codes 😛

    • This reply was modified 3 months ago by DeeLucky.
    March 26, 2018 at 11:40 #22988
    Rami
    Keymaster

    I see. Perhaps there is some minor flaw then. Certainly you can safely ignore the None events.

    March 27, 2018 at 20:07 #23003
    DeeLucky
    Participant

    I’m getting a lot of bugs in:
    NullReferenceException: Object reference not set to an instance of an object
    Apex.Steering.Components.SteerForPathComponent.TrimPath (Apex.PathFinding.Path path) (at Assets/Apex/Apex Path/Scripts/Steering/Components/SteerForPathComponent.cs:698)

    When using grids created with Grid Field Utility.
    How to resolve this issue?

    March 28, 2018 at 10:17 #23005
    Rami
    Keymaster

    That exception is caused by the _currentGrid variable being null, most likely due to the agent being off-grid or somehow getting an invalid path. Before the TrimPath method is called, through SetPath, _currentGrid is resolved from the first node in the path. Make sure the navigating agent is on a valid grid.

    March 28, 2018 at 13:10 #23007
    DeeLucky
    Participant

    Okay, that was the problem with me not initializing all the grids I need.
    The next issue I’ve got that my agents seem to ignore the portals.
    https://gyazo.com/fe909eb94009dc8d95801fe02ccc95c0

    I’ve set the grid portal to be exclusive with correct attributes, but they still seem to ignore it.
    Are there any options that agent needs to have to access the portals?

    March 29, 2018 at 15:20 #23011
    DeeLucky
    Participant

    Any solutions?

You must be logged in to reply to this topic.