15 January 2015

Navmeshes

public var Target : Transform;


GetComponent(NavMeshAgent).destination = Target.position;

Appending these two lines to the enemy script allows it to navigate the world. After baking a navmesh, the dummy object will move towards the player. This created an issue where the dummy cube would ignore colliders and sit in the same spot as the player. To solve this issue I applied a NavMesh Obstacle to the player.


As the dummy cube can now not reach the player's space it will stop just short, which is still close enough for the player to interact (read: Stab) with it. To reduce any stress on the machine later on, the portion of the script dealing with enemy death now contains the line

  GetComponent(NavMeshAgent) .enabled = false;

This means that the dummy cube will no longer attempt to path towards the player from under the game plane.

No comments:

Post a Comment