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
Share
Go down
Member [Lv. 0]
Member [Lv. 0]
Posts : 1
Points : 1501
Rep : 0
Join date : 2014-06-09
View user profile

Soldier AI (ASKING NOT GIVING)

on Wed Jun 25, 2014 12:43 pm
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
avatar
Moderator
Moderator
Posts : 329
Points : 2171
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Re: Soldier AI (ASKING NOT GIVING)

on Thu Jun 26, 2014 5:03 am
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
avatar
Moderator
Moderator
Posts : 329
Points : 2171
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Re: Soldier AI (ASKING NOT GIVING)

on Thu Jun 26, 2014 5:03 am
Screenshot:
avatar
Moderator
Moderator
Posts : 329
Points : 2171
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Re: Soldier AI (ASKING NOT GIVING)

on Thu Jun 26, 2014 5:07 am
And welcome to unityninja! Smile
Member [Lv. 2]
Member [Lv. 2]
Posts : 9
Points : 1195
Rep : 0
Join date : 2015-04-19
View user profile

Re: Soldier AI (ASKING NOT GIVING)

on Sun Apr 26, 2015 10:54 am
Thanks For The Script!
But Enemy Doesn't Move When I Moving.
I Don't Have Programming Language, Please Help me!
avatar
{SUPER MEMBER}-LV.4
{SUPER MEMBER}-LV.4
Posts : 53
Points : 1524
Rep : 11
Join date : 2015-01-18
Age : 41
Location : Italia
View user profile

Re: Soldier AI (ASKING NOT GIVING)

on Thu Apr 30, 2015 4:22 pm
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.]
Member [Lv. 2]
Member [Lv. 2]
Posts : 9
Points : 1195
Rep : 0
Join date : 2015-04-19
View user profile

Re: Soldier AI (ASKING NOT GIVING)

on Fri May 01, 2015 3:14 am
Thanks For Your Kind Help!
Member [Lv. 2]
Member [Lv. 2]
Posts : 14
Points : 1281
Rep : 0
Join date : 2015-03-07
Age : 16
Location : Sri Lanka
View user profile

Re: Soldier AI (ASKING NOT GIVING)

on Sun May 31, 2015 5:46 pm
good job! Laughing Laughing Laughing Laughing Laughing Laughing
Back to top
Permissions in this forum:
You cannot reply to topics in this forum