ok, i'm using flash 5.
this is the very beggining stages of a game, trying to get the hit detection for walking around and what not working. but objects sometimes randomly can still move through walls. if anyone could help me out that would be rad.
here's what i have.
in the frame, the only code is:
_root.wallcount=0;
stop ();
the walls are simplys squares/rectangels. make as many as you want, dont name them, their script is simply:
onClipEvent(load) {
_root.wallcount++;
this._name=_root.wallcount;
}
your character who is controlld by the arrow keys should be a square with this script and be named "c":
onClipEvent(load) {
this.speed=5;
}
onClipEvent(enterFrame) {
if(Key.isDown(Key.RIGHT)) {this.xmove+=this.speed};
if(Key.isDown(Key.LEFT)) {this.xmove-=this.speed};
if(Key.isDown(Key.DOWN)) {this.ymove+=this.speed};
if(Key.isDown(Key.UP)) {this.ymove-=this.speed};
this._x+=this.xmove;
this._y+=this.ymove;
for(i=0;i<=_root.wallcount;i++) {
if(Math.abs(this._X-_root[i]._x)<(this._wi
dth/2+_root[i]._width/2)) {
if(Math.abs(this._y-_root[i]._y)<(this._he
ight/2+_root[i]._height/2)) {
if(Math.abs(this._X-this.xmove-_root[i]._x
)>=(this._width/2+_root[i]._width/2) and Math.abs(this._y-_root[i]._y)<(this._heigh
t/2+_root[i]._height/2)) {
this._x-=this.xmove;
this.dif=Math.abs(this._X-_root[i]._x)-(th
is._width/2+_root[i]._width/2);
if(this.xmove>0) {this._x+=this.dif};
if(this.xmove<0) {this._x-=this.dif-.03};
} else {
this._y-=this.ymove;
this.dif=Math.abs(this._y-_root[i]._y)-(th
is._height/2+_root[i]._height/2);
if(this.ymove>0) {this._y+=this.dif};
if(this.ymove<0) {this._y-=this.dif-.03};
}
_root.box._rotation+=5;
}
}
}
this.xmove=0;
this.ymove=0;
}
and finaly an "enemy" that follows the player. should be a square with this script:
onClipEvent(load) {
this.speed=3;
}
onClipEvent(enterFrame) {
this.xd=this._X-_root.c._x;
this.yd=this._y-_root.c._y;
this.h=Math.sqrt(((this._X-_root.c._x)*(th
is._X-_root.c._x))+((this._y-_root.c._y)*(
this._y-_root.c._y)));
this.xmove=this.xd*(this.speed/this.h)*-1;
this.ymove=this.yd*(this.speed/this.h)*-1;
this._x+=this.xmove;
this._y+=this.ymove;
for(i=0;i<=_root.wallcount;i++) {
if(Math.abs(this._X-_root[i]._x)<(this._wi
dth/2+_root[i]._width/2)) {
if(Math.abs(this._y-_root[i]._y)<(this._he
ight/2+_root[i]._height/2)) {
if(Math.abs(this._X-this.xmove-_root[i]._x
)>=(this._width/2+_root[i]._width/2) and Math.abs(this._y-_root[i]._y)<(this._heigh
t/2+_root[i]._height/2)) {
this._x-=this.xmove;
this.dif=Math.abs(this._X-_root[i]._x)-(th
is._width/2+_root[i]._width/2);
if(this.xmove>0) {this._x+=this.dif+.03};
if(this.xmove<0) {this._x-=this.dif-.03};
} else {
this._y-=this.ymove;
this.dif=Math.abs(this._y-_root[i]._y)-(th
is._height/2+_root[i]._height/2);
if(this.ymove>0) {this._y+=this.dif+.03};
if(this.ymove<0) {this._y-=this.dif-.03};
}
_root.box._rotation+=5;
}
}
}
this.xmove=0;
this.ymove=0;
}
or you could just download the FLA if it will let me atach it...
which it won't. rename the attached image to a .fla maybe?
nope... guess i'll just have to put it online...
get the FLA here http://chadicus.free..e.com/hitdetect2.fla
check out the SWF of what i'm talking about here. .http://chadicus.free..e.com/hitdetect2.sw
f
any help would be awesome in making these things not jump around when they touch walls, or go through the walls