- Home /
Enemies should check if they are line of side to the player before attacking.
Hey guys, im making a video game where the player gets attacked from enemies with a wave system. I have melee enemies and ranged enemies and the problem is they always stand behind the melee ones. For example i added a image orange are the range enemies, black the melee ones and grey is the player. I want that the ranged ones go sideways until they are in line of sight to the player. Because i want to use projectiles that they shoot to the player and they shouldn't shoot them in the melee enemies, how can i code this? I use the NavAgent, baked my terrain under the navigation tab, the game is 3D and I have a simple followplayer script: (thank you very much!)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyFollow : MonoBehaviour
{
public NavMeshAgent enemy;
public Transform player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
enemy.SetDestination(player.position);
}
}
Your answer
Follow this Question
Related Questions
Enemy raycast detection 0 Answers
Enemy Ai Field of View 0 Answers
enemy raycast to detect player 1 Answer
AI Field of vision 1 Answer
Another Raycast Issue. 0 Answers