Hi, is there any way to cancel an OffMeshLink while the agent is on it already and waiting for it to be completed?
Well, I know that my question is vague so please let me describe it through an example.
OK here is my scenario: I have two rooms (room A and room B) which are connected via a door. Also I have a keypad on the wall of room A which unlocks the door. I’ll find this keypad later, using a script that is attached to the door. Finally I have an agent that I want to move him from room A to room B. The door may be locked, so the agent should check the door and if it’s locked, he should change his way to the keypad, which is on the wall, to unlock the door and then continue his way through the door to reach room B.
Here is my approach:
I’ve connected both rooms NavMesh together via an OffMeshLink. Tending to move the agent, I set the destination to room B. Not to mention that I’ve turned off NavMeshAgent.autoTraverseOffMeshLink
so I can handle the movement myself. I check if there’s any OffMeshLink through the path using NavMeshAgent.nextOffMeshLinkData
. This way I can access to the door and its script to find out if it’s locked or not:
- If the door isn’t locked, then on the moment of reaching the door, the agent will pass through the door simply (I’ll complete the OffMeshLink after my movement using
NavMeshAgent.CompleteOffMeshLink
). - If the door is locked, then the agent will change his way toward the keypad (I’ll reset the destination to the keypad position). He will invoke the keypad to unlock the door and then continue his way toward the door and finally the other room (I’ll reset the destination back to room B).
Now the problem is that if the agent is near the OffMeshLink already when I set the destination to room B, then NavMeshAgent.nextOffMeshLinkData
won’t get me valid information regarding the OffMeshLink, because he’s currently on the OffMeshLink and there isn’t any other OffMeshLink along the way. However, NavMeshAgent.isOnOffMeshLink
is false unless I set the destination. It means there’s no way for me to find out about the door status before reaching the OffMeshLink. In this situation the agent will freeze until I complete the OffMeshLink, which is awkward (Passing through an unlocked door?! It’s ridiculous).
I thought maybe I’d to cancel the OffMeshLink and set the destination to the keypad, but unfortunately there is no way to cancel an OffMeshLink while the agent is waiting for it to be completed.
What’s the solution? Should I follow another approach? I’m thinking of using two OffMeshLinks instead of one and put each one on one side of the door, but it seems to dirty.
Any help would be appreciated.