I’ve written some code that moves an object around the screen by clicking the mouse where you want the object to go. Also when the object hits an obstacle a function is called to move the object around the obstacle before continuing on to the original destination. Here is the part of the code which is acting a bit weird:
if (_angle >= 0 && _angle < 90 && croc.y < (thing.y + thing.height - 5)){
_targetPointX2 = (thing.x + thing.width);
_targetPointY2 = (thing.y - croc.height);
trace("targetPointY2 is " + _targetPointY2);
this.addEventListener(Event.ENTER_FRAME, movey6);
}
private function movey6(evt:Event) {
trace("targetPointY2 is " + _targetPointY2);
if (_mover.y > _targetPointY2){
_mover.y -= _speed;
} else {
_mover.x += _speed;
}
if (_mover.x > _targetPointX2){
this.addEventListener(Event.ENTER_FRAME, movey);
_clickable.addEventListener(MouseEvent.MOUSE_UP, newTarget);
this.removeEventListener(Event.ENTER_FRAME, movey6);
}
}
When ‘_targetPointY2’ is traced at the if statement it comes up as the correct point of about 370 but then for some reason when it is traced at function ‘movey6’ it comes up as 451. I’ve given myself a good headache trying to work out why so any help would be appreciated