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?