ForumsProgramming ForumHelp with AI and Walls!

2 3446
Dannydaninja
offline
Dannydaninja
948 posts
Nomad

My Evil Zombie seems to be going threw walls, I hate NO idea why, but I've tried everything my as2 knowledge knows. Can somebody please fix this code for it to work? It's the last thing I need to do then my awesome adventure game engine is complete and I can finally make another game, You will be put in the credits if you fix this code!

onClipEvent(load){
spd=5;
}
onClipEvent(enterFrame){
if (this.hitTest(_root.player)) {
_root.gotoAndStop(2);
}
while (_root.wall.hitTest(_x, _y+radius, true)) {
_y--;
}
while (_root.wall.hitTest(_x, _y-radius, true)) {
_y++;
}
while (_root.wall.hitTest(_x-radius, _y, true)) {
_x++;
}
while (_root.wall.hitTest(_x+radius, _y, true)) {
_x--;
}
Xdiff=_parent.player._x-_x;
Ydiff=_parent.player._y-_y;
radAngle=Math.atan2(Ydiff,Xdiff);
_rotation=int((radAngle*360/(2*Math.PI))+90);
updateAfterEvent();
if(this.hitTest(_parent.nothing)){
}else{
if(_rotation>180){
_y+=(spd*Math.cos(Math.PI/180*_rotation));
_x-=(spd*Math.sin(Math.PI/180*_rotation));
}else{
_y-=(spd*Math.cos(Math.PI/180*_rotation));
_x+=(spd*Math.sin(Math.PI/180*_rotation));
}
}
}

  • 2 Replies
abarrow
offline
abarrow
22 posts
Nomad

Is your spd variable ever greater than the width of the walls?

Dannydaninja
offline
Dannydaninja
948 posts
Nomad

Never mind guy, a helpful user from Kongregate found the problem, it was all about the radius

Showing 1-2 of 2