Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

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

  1. Nitzaproductions

    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);
    27.         playeranima.animation.CrossFade("attack");
    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;
    36.    playeranima.animation.CrossFade("run");
    37.    if (distanceSpot <= 0.6){
    38.    playeranima.animation.Play("idle"); 
    39.    }
    40.      }
    41.                  
    42.  
    43. }
    44.  
     
    Last edited: Feb 28, 2013
  2. Venged

    Venged

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

    Nitzaproductions

    Joined:
    Jan 10, 2013
    Posts:
    36
    really?! im happy :)
     
  4. Nitzaproductions

    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 :)
     
  5. Nitzaproductions

    Nitzaproductions

    Joined:
    Jan 10, 2013
    Posts:
    36
  6. Nitzaproductions

    Nitzaproductions

    Joined:
    Jan 10, 2013
    Posts:
    36
  7. SKR

    SKR

    Joined:
    Apr 2, 2013
    Posts:
    9
    try it!!! it works i did :)
     
  8. VeeBeeMee

    VeeBeeMee

    Joined:
    Apr 21, 2013
    Posts:
    5
    Great stuff!
     
  9. NikoBusiness

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289
    im glad that i helped!
     
  10. rockysam888

    rockysam888

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

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289