- Home /
NavMesh Agent Pushes Objects Through Floor
I have in my game a simple enemy character that uses a NavMesh Agent and a movement script to move towards the player. That works fine, but appears to be creating another issue. The NavMesh Agent and script are attached to a cube that serves as the enemy's torso, and underneath it are two more cubes, childed to the torso, that are legs. When the enemy moves, the legs are pushed partially through the floor of my map.
Honestly, I don't know for certain that the NavMesh is the cause of this, but it's the only answer I can come up with. When the object doesn't have a NavMesh or movement script on it, the legs rest on top of the floor as they should. Any ideas as to why this is happening and how I can resolve it? For reference, here is the enemy movement script attached to the torso:
using UnityEngine;
using System.Collections;
public class EnemyMovement : MonoBehaviour
{
Transform player;
NavMeshAgent agent;
void Awake()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
agent = GetComponent<NavMeshAgent>();
}
void OnTriggerStay()
{
agent.SetDestination(player.position);
}
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "MagShot")
{
agent.SetDestination(player.position);
}
}
}
Answer by csgeorge · Feb 24, 2016 at 04:00 AM
I was able to solve the issue by increasing the BaseOffset variable in the Nav Mesh Agent component.
Your answer
Follow this Question
Related Questions
Navmesh Agent velocity VS physics 1 Answer
Allow navmesh agents to be pushed off navmesh 1 Answer
Navmesh sometimes falling through world when enabled 0 Answers
When a gameobject is destroyed a chunk of the navmesh gets destroyed 2 Answers
NavMeshAgent not fully reaching destination, thus it won't delete itself when it gets there 1 Answer