x


call in script if enemy comes from behind or from front

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;} } }

}

more ▼

asked Jul 06 '12 at 01:49 PM

wolga2 gravatar image

wolga2
-64 3 7 12

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x74
x15

asked: Jul 06 '12 at 01:49 PM

Seen: 266 times

Last Updated: Jul 06 '12 at 01:49 PM