Forum Topic: AI help

(133 views • 5 replies)

This topic is 1 page long.

<< < > >>
Mad as Hell

rinoo

Reply To Post Reply & Quote

Posted at: 11/8/09 10:55 AM

rinoo NEUTRAL LEVEL 02

Sign-Up: 08/17/09

Posts: 10

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 it 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")
;

} 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")
;
}
// follow the character within boundaries
if (this._x>=1200) {
this = 0;
}
if (this._x<_root.player._x && _root.player._x-this._x<300) {
this._x += 3;
this.dir = 1;

// follow the character within boundaries part2
} else {
if (this._x<=-2150) {
this = 0;
}
if (this._x>_root.player._x && this._x-_root.player._x<300) {
this._x -= 3;
this.dir = -1;

}
}
}
}


None

rinoo

Reply To Post Reply & Quote

Posted at: 11/8/09 11:11 AM

rinoo NEUTRAL LEVEL 02

Sign-Up: 08/17/09

Posts: 10

made a little change

//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")
;

} 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")
;
}

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;

}
}
}
}


None

Yambanshee

Reply To Post Reply & Quote

Posted at: 11/8/09 11:17 AM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,589

i really dont follow your code, all you need is:

if(this._x<other._x-SPD){
this._x += SPD
} else if (this.x>other._x+SPD) {
this._x -= SPD
}

and something similer for the y axis

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

BillysProgrammer

Reply To Post Reply & Quote

Posted at: 11/8/09 11:27 AM

BillysProgrammer LIGHT LEVEL 16

Sign-Up: 09/17/08

Posts: 2,240

At 11/8/09 11:17 AM, Yambanshee wrote: i really dont follow your code, all you need is:

if(this._x<other._x-SPD){
this._x += SPD
} else if (this.x>other._x+SPD) {
this._x -= SPD
}

and something similer for the y axis

What is the point of posting this when I myself can tell you are unclear if this is corect yourself. I know of a tutorial on here and I just need to find a link, I will post it once I find it again.


None

grafik2d

Reply To Post Reply & Quote

Posted at: 11/8/09 02:20 PM

grafik2d NEUTRAL LEVEL 10

Sign-Up: 06/29/04

Posts: 176

First of all the reason why the code is not clear is that you don't understand the basis of AS2, your trying to write a story by throwing a bunch of random words on a fridge. Try this and that and also AS:Main (you might need to look at another page for the beginner stuff)


None

rinoo

Reply To Post Reply & Quote

Posted at: 11/8/09 03:08 PM

rinoo NEUTRAL LEVEL 02

Sign-Up: 08/17/09

Posts: 10

thanks, but this is not what i am looking for.


All times are Eastern Standard Time (GMT -5) | Current Time: 06:50 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!