x


help with AI avoidance script

if(Vector3.Distance(target.position, myTransform.position) < range && Vector3.Distance(target.position, myTransform.position) > attackRange){

var hit : RaycastHit;

if(Physics.Linecast(myTransform.position,target.position,hit)){ 

         if(hit.collider.gameObject.tag == "Player"){

          myTransform.LookAt(Vector3(target.position.x, myTransform.position.y, target.position.z));

          myTransform.localEulerAngles = Vector3(0,myTransform.localEulerAngles.y,0);

          myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;

         }

         else{

         myTransform.position += myTransform.right * moveSpeed * Time.deltaTime;



       }





       }



}

the original purpose of the hit check was to stop the enemies from colliding, which it did, only to have 1 enemy stop whenever it was behind the other enemy.. so I thought I would have him run around the side (the else function), you can move around in a way to get them to overlap again which was what i was trying to prevent in the first place.. so question is,, do I need to do a 2nd raycast in the else or is there a better way to do this, Thanks

more ▼

asked Jan 03 '12 at 04:35 AM

JimmyPOO gravatar image

JimmyPOO
1 2 2 2

(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:

x2505
x1535
x1374
x960
x252

asked: Jan 03 '12 at 04:35 AM

Seen: 597 times

Last Updated: Jan 03 '12 at 04:35 AM