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);
}
}

Have you tried to rebake the Navmesh ?
– HelliumHave you checked the agent height in the bake settings, by default it is 2, and that may be too much for your sheep model.
– Munchy2007no I mean, do you first click on the actual window where the games is, just on the window. It might be focused on editor still.
– danivdwerf