Tank not moving towards player

HI, I’m pretty new to Unity and have just started trying to use NavMeshAgent. i’m trying to make my enemy (A tank) move towards the player, but at the moment it kinda just sits then until it is hit and slides away. I think that means that my NavMesh is alright but my script is off? any help would be great thanks :slight_smile:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

namespace BiddiscombeOlsson
public class SoldierControl : MonoBehaviour
public bool playerInRange;
public float thrust = 200f;
public float dampening = 2.5f;

	void Update()
		// If the player is in range ..
		if (playerInRange == true)
            // .. find the player's position
            Transform targetLocation = GameObject.FindWithTag("Player").transform;
            // Set the reference to the soldier's navMeshAgent component
            UnityEngine.AI.NavMeshAgent navAgent = gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();

            // Set the destination for the navAgent

			// This makes the turret look at the player's X and Z but ignores the Y
			Vector3 playerPosition = new Vector3(targetLocation.position.x, transform.position.y, targetLocation.position.z);
            Vector3 aim = playerPosition - transform.position;
            Quaternion rotate = Quaternion.LookRotation(aim);

            // Lerp rotation and include the dampening to ease motion
            transform.rotation = Quaternion.Lerp(transform.rotation, rotate, Time.deltaTime * dampening);


Thanks, can post other information if needed

Your code is fine. i think you declare the boolean playerInRange is not true in the inspector, thats why your NavmeshAgent is not moving.

Make Sure playerInRange is checked in the inspector.

other thing is that you don’t need the true check in the condition if (playerInRange == true), its true you can just write.

if (playerInRange)

EDIT 1 : If that not move than another Update is blocking the Navmesh agent to move. Anywhere in the other script your playerInRange is false thats why Navmesh sits.

Note: Navmesh work only on Baked Areas which are marked as static.