I’ve been trying to work this out for days and I’m starting to despair,
The enemies chase me when they get so close, but for some reason when they’re running up/down a slope if the enemies collide they start floating upwards :S
Thanks!
Here is a screenshot:
Here is the enemy code:
//private var nav : NavMeshAgent;
var anim : Animator;
var awareDistance : float = 25.0;
var chaseDistance : float = 20.0;
var stopChaseDistance : float = 1;
var player : Transform;
var runSpeed : float = 15.0;
//enum AIStatus {idle = 0, Scared = 1} //for some reason it doesn't need this :S but it works
private var status = AIStatus.idle;
private var moveDirection = Vector3.zero;
function Awake()
{
anim = GetComponent(Animator);
}
function Update()
{
CheckStatus();
switch(status)
{
case AIStatus.idle:
idle();
break;
case AIStatus.Scared:
ChasePlayer();
break;
}
}
function idle()
{
anim.SetBool("Running",false);
}
function ChasePlayer()
{
transform.LookAt(player);
transform.position += transform.forward*runSpeed*Time.deltaTime;
anim.SetBool("Running",true);
}
function CheckStatus()
{
var dist = (player.position - transform.position).magnitude;
if(dist < chaseDistance dist > stopChaseDistance)
{
status = AIStatus.Scared;
}
if (dist > awareDistance)
{
status = AIStatus.idle;
}
if (dist < stopChaseDistance)
{
status = AIStatus.idle;//CHANGE TO ATTACK FUNCTION LATER
}
}