Search Unity

Enemy AI help

Discussion in 'Scripting' started by monkey22mm, Aug 26, 2012.

  1. monkey22mm

    monkey22mm

    Joined:
    Aug 25, 2012
    Posts:
    11
    i need help i need to make a enemy AI to follow the enemy,teleport every so often,cant go through walls im new to scripting but i dont know alot of stuff so if anyone can help me that would be great here is the script i use thanks :DDDDDDDDDD


    #pragma strict

    var target : Transform; //the enemy's target
    var moveSpeed = 3; //move speed
    var rotationSpeed = 3; //speed of turning

    var myTransform : Transform; //current transform data of this enemy

    function Awake()
    {
    myTransform = transform; //cache transform data for easy access/preformance
    }

    function Start()
    {
    target = GameObject.FindWithTag("Player").transform; //target the player

    }

    function Update () {
    //rotate to look at the player
    myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
    Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);

    //move towards the player
    myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;


    }
     
  2. RaysFan

    RaysFan

    Joined:
    Jul 5, 2012
    Posts:
    27
    Well, I have followed tutorial on Enemy AI script, it's C#, but I can get it to you! If you want script, here! http://dl.dropbox.com/u/92094772/EnemyAI.cs

    It should work completely! But make sure you create a new tag for your enemy as "Enemy", and create a tag for player named, "Player"! Hope this helps you! NOTE: Unity will throw you a error until you add the enemy's target! :D
     
    Last edited: Aug 27, 2012
  3. RaysFan

    RaysFan

    Joined:
    Jul 5, 2012
    Posts:
    27
    And also make sure if you use the script to name it EnemyAI!