NavMeshAgent and moving on moving objects

Hey,
I got the following issue:
I use the NavMeshSurface to generate the surface on the object. Then I setup a simple AI movment via clicks to make him move. If the platform is idle he can move but as soon it moves the unit is shifting to the edge of the moving platform and staying there. Here is the Character Script which I use very simple:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class Character : MonoBehaviour {

    private bool unitSelected = true;

    private float health;

    private Vector3 Destination;
    private Task task;
    private Inventory inventory;

    private NavMeshAgent agent;

    // Use this for initialization
    void Start () {
        agent = GetComponent<NavMeshAgent>();
      
    }

    // Update is called once per frame
    void Update()
    {
        if (unitSelected)
        {
           // Debug.Log("isSelected");
            if (Input.GetKey(KeyCode.Mouse1))
            {
                //Debug.Log("PressedKey");
                RaycastHit hit;
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, 100))
                {
                    if (hit.transform.tag.Equals("Ground"))
                    {
                        //Debug.Log("HitGround at " + hit.transform.position);
                        makeMove(hit.point);
                    }
                }
            }
        }
    }


    void makeMove(Vector3 desti)
    {
        Debug.Log("MakeMove to : " + desti);
        //agent.destination = destination;
        agent.SetDestination(desti);
      
    }
}

To move the platform its just one stmt in the update method:

        this.transform.position = Vector3.MoveTowards(this.transform.position, pos.transform.position, Time.deltaTime);

Any Ideas where this issue came from?

Okay… for some reason it now works… I setup the things again and hurray it does waht it should.
But I run into the next issue since the platform is moving the unit go back to the old world position and dont stay at the local grid of the moving platform.

have I to reupdate the position to the navmeshagent while its moving all the time or is there a work around?

You’re describing a use-case that is not supported yet.
The internal representation of the navmesh cannot doesn’t recognize the move. It’s treated as if you remove the navmesh and add a new navmesh right next to the previous one.

To reliably move a navmesh you need a Move method (similar to the Move method on rigidbodies) - but it’s not supported yet.

(it’s also mentioned in the FAQ here : GitHub - Unity-Technologies/NavMeshComponents: High Level API Components for Runtime NavMesh Building )

There is nothing wrong with this script. It must be on the generated surface of the platform or somewhere else, this script reads perfectly fine, in fact you can use default ethan with that script and a navemesh and a plane and he moves just fine.

As far as navmeshagent.move, it definitely does exist… wtf?

Set tthe Character’s transform.parent = platform.transform ?

It work’s for me, when I put a character on a moving boat.

I’m also wondering how to do this. According to this video (8:59, Unite Europe 2017) it says it is possible to move an Object with a NavMeshAgent that is, let’s say, walking on a moving platform in realtime. But it will be resource intensive.

@niflying , can you provide me more details on how you successfully did this with a moving Boat?

1 Like

bump