# [VIDEO TUTORIAL] (FULL FREE) - EnemyAI with Animations PathFinding Patrol

Discussion in 'Community Learning & Teaching' started by Nitzaproductions, Feb 27, 2013.

1. ### Nitzaproductions

Joined:
Jan 10, 2013
Posts:
36
hello i provide a free tutorial for unity users! it may not be the best but i tryed to do what i was looking for a few months ago!
and i think it is gonna help a lot of people!

so here is the video tutorial

DONT TURN OFF ANNOTATIONS IF U WANT TO SUCCESS TO THE TUTORIAL

HERE IS MY PROTOTYPE

SO IF THIS TUTORIAL MADE U SUCCESS PLEASE SUBSCIBE MY CHANNEL! THANKS

Here Is The Script
Code (csharp):
1. var target : Transform;
2. var playeranima : GameObject;
3. private var distance : float;
4. var rotationSpeed : int;
5. var myTransform : Transform;
6. public var spartanSpot : Transform;
7. private var distanceSpot : float;
8.
9.
10. function Start() {
11. rotationSpeed = 4;
12. }
13.
14. function Update()
15. {
16. var hit : RaycastHit;
17. distance = Vector3.Distance(target.transform.position, transform.position);
18. distanceSpot = Vector3.Distance(spartanSpot.transform.position, transform.position);
19. if (distance <= 5){
20.     Debug.DrawRay(transform.position, hit.point, Color.green);
21.     GetComponent(NavMeshAgent).destination = target.position;
22.         if (distance > 2.1) {
23.             playeranima.animation.Play("run");
24.                           }
25.         else    {
26.         myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
28.         if(Physics.Raycast(transform.position, transform.forward, hit , 10)){
29.         Debug.DrawLine(transform.position, transform.forward, Color.green);
30.         Debug.Log("hited");
31.         }
32.                 }
33.         }
34. else {
35.    GetComponent(NavMeshAgent).destination = spartanSpot.position;
37.    if (distanceSpot <= 0.6){
38.    playeranima.animation.Play("idle");
39.    }
40.      }
41.
42.
43. }
44.

Last edited: Feb 28, 2013
2. ### Venged

Joined:
Oct 24, 2010
Posts:
500
Thanks! looks great!

3. ### Nitzaproductions

Joined:
Jan 10, 2013
Posts:
36
really?! im happy

4. ### Nitzaproductions

Joined:
Jan 10, 2013
Posts:
36
if you liked the tutorial im gonna make the script do more things that u can tell me to add! and make a tutorial to help you use it

Joined:
Jan 10, 2013
Posts:
36
up

Joined:
Jan 10, 2013
Posts:
36
up

7. ### SKR

Joined:
Apr 2, 2013
Posts:
9
try it!!! it works i did

Joined:
Apr 21, 2013
Posts:
5
Great stuff!

Joined:
May 6, 2013
Posts:
289

Joined:
Jul 28, 2009
Posts:
650
Thank you.