Question by
davit_goder · Aug 31, 2016 at 01:07 PM ·
movementnavmesh
moving in y axis with nav mesh
hello, I have simple movement script that works very well in x and z, but when my object reaches target (which is in the air) it stops below it. how can I fix it? Thanks!
using UnityEngine;
using System.Collections;
public class new_R : MonoBehaviour
{
public Transform t;
public float timer;
public int newtarget;
public float speed;
public NavMeshAgent nav;
public Vector3 target;
void Start()
{
nav = gameObject.GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
timer += Time.deltaTime;
if (timer >= newtarget)
{
newtarget1();
}
timer = 0;
}
void newtarget1()
{
float myx = gameObject.transform.position.x;
float myz = gameObject.transform.position.z;
float xpos = t.position.x;
float ypos = t.position.z;
float zpos = t.position.z;
target = new Vector3(xpos, ypos, zpos);
nav.SetDestination(target);
}
}
Comment