ntt
November 28, 2002, 9:25pm
1
Hey everyone, first will you please look at this- http://www.angelfire.com/sd2/flashstuff/project.html
im trying to make some enemies that will move around randomly and NOT walk over the walls inside the movieclip named ‘back’.
now i tried to do this but the guy walks over the walls and stuff, plus he doesnt randomly move, it just moves in the same 3 ways. can anyone please help me out here?
Thank You!!
system
November 30, 2002, 5:37am
2
What code are you currently using on the main character?
What code are you attempting to use on the antagonist?
system
November 30, 2002, 8:02pm
3
hi, you can look at the fla here. WARNING- the code is very sloppy and disorganized
http://www.angelfire.com/sd2/flashstuff/opensource.fla
i think it may have something to do with the scrolling because if i test it outside of my game it works perfectly. someone suggested i use localToGlobal. problem is, i dont know what the code should look like then…
Thanks For your help
system
November 30, 2002, 8:04pm
4
oh by the way the code for the guy im trying to add random movement isnt in that fla.
the code is
onClipEvent (load) {
hitme = 0;
position = new Array(4, 0, 0, 0, 4, 90, -4, 0, 180, 0, -4, -90);
positioncounter = 0;
speed_x = position[positioncounter];
speed_y = position[positioncounter+1];
gotoAndStop (2);
function testhit () {
// hittest the wall
if (_root.back.hitTest(this._x+speed_x+30, this._y+speed_y, true) and hitme<>1 ) {
hitme = 1;
}
if (_root.back.hitTest(this._x+speed_x-30, this._y+speed_y, true) and hitme<>1 ) {
hitme = 1;
}
if (_root.back.hitTest(this._x+speed_x, this._y+speed_y+30, true) and hitme<>1 ) {
hitme = 1;
}
if (_root.back.hitTest(this._x+speed_x, this._y+speed_y-30, true) and hitme<>1 ) {
hitme = 1;
}
if (_root.back.hitTest(this._x+speed_x+30, this._y+speed_y+30, true) and hitme<>1 ) {
hitme = 1;
}
if (_root.back.hitTest(this._x+speed_x+30, this._y+speed_y-30, true) and hitme<>1 ) {
hitme = 1;
}
if (_root.back.hitTest(this._x-30+speed_x, this._y+speed_y+30, true) and hitme<>1 ) {
hitme = 1;
}
if (_root.back.hitTest(this._x-30+speed_x, this._y+speed_y-30, true) and hitme<>1 ) {
hitme = 1;
}
}
}
onClipEvent (enterFrame) {
// see the hero
distance = Math.sqrt((this._x-_root.hero._x)*(this._x-_root.hero._x)+(this._y-_root.hero._y)*(this._y-_root.hero._y));
angle = Math.acos((_root.hero._y-this._y)/distance)*180/Math.PI;
if (this._x<_root.hero._x) {
angle = -angle;
}
if (distance<200 and Math.abs(angle-this._rotation+90)<60) {
_root.detected = "YES";
} else {
_root.detected = "NO";
}
if (hitme == 0) {
testhit();
if (hitme == 0) {
// moving
setProperty (this, _x, this._x+speed_x);
setProperty (this, _y, this._y+speed_y);
}
if (random(100)<1) {
hitme = 1;
}
}
// i hit the wall
if (hitme<>0) {
gotoAndStop (1);
hitme = hitme+1;
// stop to think
if (hitme == 20) {
hitme = 0;
if (random(2) == 1) {
// turn left
positioncounternew = positioncounter-3;
if (positioncounternew<0) {
positioncounternew = 9;
}
speed_x = position[positioncounternew];
speed_y = position[positioncounternew+1];
setProperty ("", _rotation, position[positioncounternew+2]);
testhit();
} else {
// turn right
positioncounternew = positioncounter+3;
if (positioncounternew>9) {
positioncounternew = 0;
}
speed_x = position[positioncounternew];
speed_y = position[positioncounternew+1];
setProperty ("", _rotation, position[positioncounternew+2]);
testhit();
}
if (hitme == 1) {
hitme = 19;
} else {
positioncounter = positioncounternew;
gotoAndStop (2);
}
speed_x = position[positioncounter];
speed_y = position[positioncounter+1];
setProperty ("", _rotation, position[positioncounter+2]);
}
}
}