Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

how can i make my enemy attack player and move idle

$
0
0
using UnityEngine.AI; public class EnemyMovement : MonoBehaviour { public float fov = 120f; public Transform target; public bool inSight; public float AwakeDistance = 200f; public bool AwareOFPlayer; public NavMeshAgent enemyAgent; public bool playerinVision; private void Update() { drawRay(); float playerDistance = Vector3.Distance(target.position, transform.position ); Vector3 playerDirection = target.position - transform.position; float playerAngel = Vector3.Angle(transform.forward, playerDirection); if(playerAngel <= fov/2f) { inSight = true; Debug.Log("PlayerinSight"); } else { inSight = false; } if(inSight == true && playerDistance <= AwakeDistance && playerinVision == true) { AwareOFPlayer= true; } if(AwareOFPlayer == true) { enemyAgent.SetDestination(target.position); } } void drawRay() { Vector3 playerDirection = target.position - transform.position; RaycastHit hit; if(Physics.Raycast(transform.position, playerDirection , out hit)) { if(hit.transform.tag == "Player") { playerinVision = true; }else{ playerinVision = false; } } } },using UnityEngine.AI; public class EnemyMovement : MonoBehaviour { public float fov = 120f; public Transform target; public bool inSight; public float AwakeDistance = 200f; public bool AwareOFPlayer; public NavMeshAgent enemyAgent; public bool playerinVision; private void Update() { drawRay(); float playerDistance = Vector3.Distance(target.position, transform.position ); Vector3 playerDirection = target.position - transform.position; float playerAngel = Vector3.Angle(transform.forward, playerDirection); if(playerAngel <= fov/2f) { inSight = true; Debug.Log("PlayerinSight"); } else { inSight = false; } if(inSight == true && playerDistance <= AwakeDistance && playerinVision == true) { AwareOFPlayer= true; } if(AwareOFPlayer == true) { enemyAgent.SetDestination(target.position); } } void drawRay() { Vector3 playerDirection = target.position - transform.position; RaycastHit hit; if(Physics.Raycast(transform.position, playerDirection , out hit)) { if(hit.transform.tag == "Player") { playerinVision = true; }else{ playerinVision = false; } } } }*emphasized text* ,

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>