Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here:
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
  4. Join us on Thursday, September 29, for a day with Unity's SRP teams here on the forum or on Reddit, and discuss topics around URP, HDRP, and the Scriptable Render Pipeline in general.
    Dismiss Notice

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

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

  1. N7D


    Feb 25, 2017
    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