can anyone write a script which will allow an enemy (zombie) to walk/run to person whilst it plays a walk/run animation ive only got untill christams to finnish this project so please can ayone help me?
Let's give it a shot !
class Zombi extends MonoBehaviour
{
var speed = 5.0f;
var focusDist : float = 10.0f;
var player : Transform;
private var zombiToPlayer : Vector3;
function Update()
{
zombiToPlayer = player.transform.position - transform.position;
var dist = zombiToPlayer.magnitude;
if( dist <= focusDist )
RunTowardPlayer();
else
Idle();
}
function RunTowardPlayer()
{
transform.rotation = Quaternion.LookRotation(zombiToPlayer);
gameObject.GetComponent( CharacterController ).Move( zombiToPlayer.normalized * speed * Time.deltaTime );
animation.CrossFade( "run", 0.3 );
}
function Idle()
{
animation.CrossFade( "idle", 0.3 );
}
}
You need to add a CharacterController on your zombi, and to drag-drop the player on the script (might be wise to change that into GameObject.Find...() )