- Home /
About a enemy AI in my game
Hello, i made a rader simple AI script for one of the enemys in my game, now the problem is, he is losing his colliders when the game executes. i tried to put a Character controller, and there ar still no colliders. Here is the script -
var player : GameObject;
var speed : float=6f; var range : float=10f; var hitRange : float=5f; var enemyDamage : float=10f; var rotationSpeed : float=5f; var damageTimer : float=0f;
@script RequireComponent (CharacterController)
function Update()
{ //move towards player var distance = Vector3.Distance(transform.position, player.transform.position); if(distance<=range) {
var delta = player.transform.position - transform.position; delta.Normalize(); delta.y = 0; var moveSpeed = speed Time.deltaTime; transform.position = transform.position + (delta moveSpeed);
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(delta), rotationSpeed * Time.deltaTime); transform.eulerAngles = Vector3(0, transform.eulerAngles.y, 0);
damageTimer+=Time.deltaTime;
if (distance < hitRange && damageTimer>=1.5)
{
damageTimer=0f;
player.SendMessageUpwards
("ApplyDamage", enemyDamage, SendMessageOptions.DontRequireReceiver);
}
}
}
ill be glad if some 1 would be able to help me.
Answer by kici · Jan 05, 2011 at 09:29 AM
There's nothing in the script that affects his colliders... Therefore you should work check in your inspector, for instance play the game and watch the enemy, and see if it still has its collider attached to it, if not add one... and go on from there... as I dont see any scripting for your colliders either.
well, acctually his collider is only responding to Rigid Bodies, but not for Reg. Obj (if colliders of course)