Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » FREE Project Downloads & Recources » Complete Projects » Soldier AI (ASKING NOT GIVING)

Soldier AI (ASKING NOT GIVING)

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Soldier AI (ASKING NOT GIVING) on Wed Jun 25, 2014 12:43 pm

mahmod sakhnini 2


Member [Lv. 0]
Member [Lv. 0]
Hey Guys , i need a soldier with AI so i just import it in the scene and it will work

Friendly and enemy
and Follow ....

please ....  Smile

View user profile

2 Re: Soldier AI (ASKING NOT GIVING) on Thu Jun 26, 2014 5:03 am

developer23


Moderator
Moderator
Simple Enemy AI Script (.js) This is not done by me,but I hope you like it Wink
Code:
var target : Transform; //the enemy's target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
var range : float=10f;
var range2 : float=10f;
var stop : float=0;
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
    var distance = Vector3.Distance(myTransform.position, target.position);
    if (distance<=range2 &&  distance>=range){
    myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
    Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
    }
 
 
    else if(distance<=range && distance>stop){
 
    //move towards the player
    myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
    Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
    myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
    }
    else if (distance<=stop) {
    myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
    Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
    }
 
 
}



Last edited by developer23 on Thu Jun 26, 2014 5:21 am; edited 1 time in total

View user profile http://masterdevelopers.altervista.org/

3 Re: Soldier AI (ASKING NOT GIVING) on Thu Jun 26, 2014 5:03 am

developer23


Moderator
Moderator
Screenshot:

View user profile http://masterdevelopers.altervista.org/

4 Re: Soldier AI (ASKING NOT GIVING) on Thu Jun 26, 2014 5:07 am

developer23


Moderator
Moderator
And welcome to unityninja! Smile

View user profile http://masterdevelopers.altervista.org/

5 Re: Soldier AI (ASKING NOT GIVING) on Sun Apr 26, 2015 10:54 am

Ana123


Member [Lv. 2]
Member [Lv. 2]
Thanks For The Script!
But Enemy Doesn't Move When I Moving.
I Don't Have Programming Language, Please Help me!

View user profile

6 Re: Soldier AI (ASKING NOT GIVING) on Thu Apr 30, 2015 4:22 pm

PitbullM


Member [Lv. 3]
Member [Lv. 3]
Trial has put the tag "Player"
you'll see that you will follow

A look at this
[You must be registered and logged in to see this link.]

View user profile

7 Re: Soldier AI (ASKING NOT GIVING) on Fri May 01, 2015 3:14 am

Ana123


Member [Lv. 2]
Member [Lv. 2]
Thanks For Your Kind Help!

View user profile

8 Re: Soldier AI (ASKING NOT GIVING) on Sun May 31, 2015 5:46 pm

Sewmina


Member [Lv. 2]
Member [Lv. 2]
good job! Laughing Laughing Laughing Laughing Laughing Laughing

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum