- Home /
Question by
GnollShaman12 · Aug 20, 2017 at 12:01 AM ·
scripting problem3dai
I'm have trouble with the ai script in standard asset
AI script taken from standard assets can only work in a short distance. I don't why this is happening, I am not an expert in 3d AI scripting. I just need someone to look it over and tell me what to remove or add in the script.
[RequireComponent(typeof (UnityEngine.AI.NavMeshAgent))]
[RequireComponent(typeof (ThirdPersonCharacter))]
public class AICharacterControl : MonoBehaviour
{
public UnityEngine.AI.NavMeshAgent agent { get; private set; } // the navmesh agent required for the path finding
public ThirdPersonCharacter character { get; private set; } // the character we are controlling
public Transform target; // target to aim for
private void Start()
{
// get the components on the object we need ( should not be null due to require component so no need to check )
agent = GetComponentInChildren<UnityEngine.AI.NavMeshAgent>();
character = GetComponent<ThirdPersonCharacter>();
agent.updateRotation = false;
agent.updatePosition = true;
target = GameObject.FindGameObjectWithTag("Player 1").transform;
}
private void Update()
{
if (target != null)
agent.SetDestination(target.position);
if (agent.remainingDistance > agent.stoppingDistance)
character.Move(agent.desiredVelocity, false, false);
else
character.Move(Vector3.zero, false, false);
}
public void SetTarget(Transform target)
{
this.target = target;
}
}
Comment
Your answer
Follow this Question
Related Questions
Accurate Projectile Leading for AI [Third person shooter] 0 Answers
Can't properly duplicate an enemy AI 0 Answers
AI help people 1 Answer
2D blade to 3D 0 Answers