ForumsProgramming ForumAI help

4 4196
rino
offline
rino
27 posts
Nomad

I am trying to make a character(1) follow another character(2) and when character(1) gets close enough to stop moving. The problem is , is that movment of the character (movie clip plays action) only works some times. Does anyone have any idea how to change it so it works.



//follow the character with movment
onClipEvent (enterFrame) {
if (this._x<_root.player._x && _root.player._x-this._x<100 or this._x>_root.player._x && this._x-_root.player._x<100) {
_root.sven.sven_body.sven_body_sword.sve nviking_sword_walking.gotoAndPlay("stop"
);
_root.sven.sven_legs.gotoAndPlay("stop&quot
;

} else {
if (this._x<_root.player._x && _root.player._x-this._x>=300 or this._x>_root.player._x && this._x-_root.player._x>=300) {
_root.sven.sven_body.sven_body_sword.sve nviking_sword_walking.gotoAndPlay("walk"
);
_root.sven.sven_legs.gotoAndPlay("walk&quot
;
}

if (this._x<_root.player._x && _root.player._x-this._x<300) {
this._x += 3;
this.dir = 1;

// follow the character part2
} else {

if (this._x>_root.player._x && this._x-_root.player._x<300) {
this._x -= 3;
this.dir = -1;

}
}
}
}

  • 4 Replies
plasmafish
offline
plasmafish
252 posts
Nomad

Are the registration points on the movie clips properly set?

kingkongbaz
offline
kingkongbaz
1 posts
Nomad

i dont now

15Master1
offline
15Master1
48 posts
Nomad

http://www.tutorialized.com/upload/20090926030412_50-50.gifhttp://www.tutorialized.com/upload/20090926030412_50-50.gifhttp://www.tutorialized.com/upload/20090926030412_50-50.gif
Tutorialized should help you...

elroy
offline
elroy
5 posts
Nomad

The AI I use is
onClipEvent (enterFrame) {
if (_root.char._y<_root.enemy._y) {
jumping = true;
} else {
jumping = false;
}
}
onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
if (_root.char._x<_root.enemy._x) {
_x -= speed;
}
if (_root.char._x>_root.enemy._x) {
_x += speed;
}
if (_root.char._y<_root.enemy._y) {
_y -= speed;
}
if (_root.char._y>_root.enemy._y) {
_y += speed;
}
}

Remember to instance name the character as "char" and the guy as "enemy." He will not do dameage to your char.

Showing 1-4 of 4