FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

descriptionSoldier AI (ASKING NOT GIVING)

more_horiz
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

descriptionRe: Soldier AI (ASKING NOT GIVING)

more_horiz
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

descriptionRe: Soldier AI (ASKING NOT GIVING)

more_horiz
Screenshot:

_________________
Game Developer
YouTube Channel: [You must be registered and logged in to see this link.]
Website: [You must be registered and logged in to see this link.]

descriptionRe: Soldier AI (ASKING NOT GIVING)

more_horiz
And welcome to unityninja! Smile

descriptionRe: Soldier AI (ASKING NOT GIVING)

more_horiz
Thanks For The Script!
But Enemy Doesn't Move When I Moving.
I Don't Have Programming Language, Please Help me!

descriptionRe: Soldier AI (ASKING NOT GIVING)

more_horiz
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.]

descriptionRe: Soldier AI (ASKING NOT GIVING)

more_horiz
Thanks For Your Kind Help!

descriptionRe: Soldier AI (ASKING NOT GIVING)

more_horiz
good job! Laughing Laughing Laughing Laughing Laughing Laughing

_________________
Embarassed Sewmina
Permissions in this forum:
You cannot reply to topics in this forum