Quantcast
Channel: Questions in topic: "behind"
Viewing all articles
Browse latest Browse all 97

call in script if enemy comes from behind or from front

$
0
0
hi! i want in a game my enemy (navmeshagent) to come towards me if he is 65 units away from me and in front of the camera. but if he comes from behind, he should just pass me by. i do not know how to call it if my enemy comes from behind or comes from the front. in my code, if the enemy comes from behind, he will turn around and come towards me, as soon as he is in front of me. could anybody help me how to write the code right? here it is: import System.Collections.Generic; var wayPoints : List.; private var currentWP = 0; var targetEnemy : Transform; var player : Transform; function Update () { var screenPos : Vector3 = cam.WorldToScreenPoint(targetEnemy.position); if (screenPos.z > 0 && screenPos.z < 65) { GetComponent(NavMeshAgent).destination = player.position; } else { GetComponent(NavMeshAgent).destination = wayPoints[currentWP].transform.position; if (GetComponent(NavMeshAgent).remainingDistance < 0.5) { currentWP++; if (currentWP > wayPoints.Count - 1) {currentWP = 0;} } } }

Viewing all articles
Browse latest Browse all 97

Trending Articles