- Home /
Duplicate Question - http://answers.unity3d.com/questions/439309/dynamically-fixing-navmeshagent-base-offset.html
NavMeshAgent, my object is floating in the air.. why?? :(
Hi guys,
I'm trying to create a simple AI to my sheep but I have some problems. My sheep is floating in the air, she is not on the ground.
Anybody have any idea how to fix it? Thanks
Sheep.cs
using UnityEngine;
using System.Collections;
public class Sheep
{
private GameObject obj;
private Object prefab;
public Sheep(string name, Vector3 position)
{
prefab = Resources.Load("Prefabs/Sheep");
obj = GameObject.Instantiate(prefab) as GameObject;
obj.name = name;
obj.transform.position = position;
obj.AddComponent<NavMeshAgent>();
obj.AddComponent<AnimalActions>();
}
}
AnimalActions.cs
using UnityEngine;
using System.Collections;
public class AnimalActions : MonoBehaviour
{
private NavMeshAgent nav;
private GameObject[] waypoints;
private int waypointIndex;
void Awake()
{
nav = GetComponent<NavMeshAgent>();
nav.obstacleAvoidanceType = ObstacleAvoidanceType.HighQualityObstacleAvoidance;
}
void Start()
{
waypoints = GameObject.FindGameObjectsWithTag("Farm");
waypointIndex = Random.Range(0, waypoints.Length);
}
void Update()
{
if (nav.remainingDistance < 0.5f)
{
Patrol();
}
}
void Patrol()
{
nav.destination = waypoints[waypointIndex].transform.position;
waypointIndex = Random.Range(0, waypoints.Length);
}
}
Yes, I already try to rebake and I got the same problem, the sheep still floating :/
and have you tried adjusting the height in the navmesh agent section? and check the collider of the sheep, try giving it a box collider if it is set to mesh
Have you checked the agent height in the bake settings, by default it is 2, and that may be too much for your sheep model.
Answer by salsa · Jun 08, 2016 at 05:39 PM
I change the height and the baseOffset
nav.height = 0.5f;
nav.baseOffset = 0;
now looks good :)
Thanks a lot :)
Follow this Question
Related Questions
3rd person camera to player 2 Answers
Navmesh pathfinding "scattering"? 1 Answer
lava growing like avalanche 1 Answer
What's a good way to find the ground normal? 1 Answer
how do i to make the ground? 1 Answer