hi, i want the enemies to instantiate at a point and then move towards a defined target and after reaching that point i want it to lookAt player and also to follow it and attack. I want it to suddenly attack the player by appearing in front of it… please guide to achieve this.
this might help.
void Update(){
//this will make the enemy move forward to the desired target
transform.LookAt( desiredTarget );
this.gameObject.transform.position += this.gameObject.transform.forward*MovementSpeed*Time.deltaTime;
if(Vector3.Distance(transform.position, desiredTarget.position) <= 0)
//you are now at the desired target.
{
transform.LookAt(Player);
this.gameObject.transform.position += this.gameObject.transform.forward*AttackingSpeed*Time.deltaTime;
//you are now moving towards the player
if(Vector3.Distance(transform.position,Player.position) <= minDist)
{
//you are now at the player's feet or somewhere close depending on your minDist.
//if you want it to teleport or something, you can add something here like:
this.gameObject.transform.position =new Vector3( Player.position.x, Player.position.y, Player.position.z - 1.0f );
// just tweak this to your desired effect.
}
}
}
i hope this helps…
this is what i was looking forward thanks…