Search Unity

Bug Setting imitated agent position using "Warp()" and "updatePosition = false" issue

Discussion in 'Navigation' started by N7D, Nov 24, 2021.

  1. N7D

    N7D

    Joined:
    Feb 25, 2017
    Posts:
    9
    I am making flying agent, the basics is it flies above the ground by having baseOffset changing while still being agent on navmesh, but it's not enough to simulate ability to fly, so I decided to check if corners of path can be skipped and fly directly from current position to such corner.

    I do that by disabling updatePosition and updateRotation and control transform manually in coroutine. And it works, it flies there (outside navmesh, but start and end points are on navmesh) and in the end I enable updates and it can go somewhere.

    BUT, it needs to be able to change direction, because the chase target is moving away while the agent stuck in coroutine. So I want to immediately put imitated agent at direct flight endpoint, so I can calculate new paths to current target position from there. This way I can scan new corner skips and change direct fly endpoint midair.

    And I found only 2 ways to set imitated agent position:

    - First one is setting nextPosition, it just doesn't work, it almost always get stuck somewhere on the path corner between current and endpoint. But it doesn't clear agent's path.
    - Second one is Warp() and it does set imitated agent position, but it clears path and for some reason it changes gameObject's position to warped one EVEN THOUGH I have updatePosition set to false...

    It seems like a bug? I have to do a workaround like this to mitigate this issue:

    Code (CSharp):
    1.         var initialPosition = npc.transform.position;
    2.         npc.agent.Warp(((IFlyerData)npc.npcData).directFlyTarget);
    3.         npc.transform.position = initialPosition;
    But in reality I would've also preferred not losing current agent's path, so both nextPosition and .Warp() produce weird results, while all I want to do is just to set agent position to Nth corner on the path.
     
    Last edited: Nov 24, 2021
    kyuskoj likes this.