I have a enemy movieClip named: enemy01. I am creating AI movement for this mc. Here is my code:
_root.enemy01.speed = 1
_root.enemy01.turnRate = .05
_root.enemy01.agroRange = 200;
_root.enemy01.mode = “follow”
_root.enemy01.distanceX = 0;
_root.enemy01.distanceY = 0;
_root.enemy01.distanceTotal = 0;
_root.enemy01.moveDistanceX = 0;
_root.enemy01.moveDistanceY = 0;
_root.enemy01.moveX = 0;
_root.enemy01.moveY = 0;
_root.enemy01.totalmove = 0;
function updatePosition(follower:_root.enemy01, target:_root.Hero) {
//I will compute the distance between follower and target
_root.enemy01.distanceX = target._x-_root.enemy01._x;
_root.enemy01.distanceY = target._y-_root.enemy01._y;
//I will get the total distance as a number
_root.enemy01.distanceTotal = Math.sqrt(_root.enemy01.distanceX * _root.enemy01.distanceX + _root.enemy01.distanceY * _root.enemy01.distanceY);
//I will check to see if agro range
if(_root.enemy01.distanceTotal <= _root.enemy01.agroRange){
_root.enemy01.moveDistanceX = _root.enemy01.turnRate * _root.enemy01.distanceX / _root.enemy01.distanceTotal;
_root.enemy01.moveDistanceY = _root.enemy01.turnRate * _root.enemy01.distanceY / _root.enemy01.distanceTotal;
_root.enemy01.moveX += _root.enemy01.moveDistanceX;
_root.enemy01.moveY += _root.enemy01.moveDistanceY;
_root.enemy01.totalmove = Math.sqrt(_root.enemy01.moveX * _root.enemy01.moveX + _root.enemy01.moveY * _root.enemy01.moveY);
_root.enemy01.moveX = _root.enemy01.speed * _root.enemy01.moveX / _root.enemy01.totalmove;
_root.enemy01.moveY = _root.enemy01.speed * _root.enemy01.moveY / _root.enemy01.totalmove;
//I will move and rotate the follower
if(_root.enemy01.mode == “follow”)
{
_root.enemy01._x += _root.enemy01.moveX;
_root.enemy01._y += _root.enemy01.moveY;
_root.enemy01._rotation = Math.atan2(_root.enemy01.moveY, _root.enemy01.moveX) * radians;
}
else if(_root.enemy01.mode == “run”)
{
_root.enemy01._x -= _root.enemy01.moveX;
_root.enemy01._y -= _root.enemy01.moveY;
_root.enemy01._rotation = (Math.atan2(_root.enemy01.moveY, _root.enemy01.moveX) * radians)+180;
}
}
}
This is the error I am getting:
The class or interface ‘_root.enemy01’ could not be loaded. function updatePosition(follower:_root.enemy01, target:_root.Hero) {
If you know how to make a movieclip move on its own easier, please be a pal and share. Thanks!