At 8/6/06 03:11 PM, Jon_0_tan wrote:
Okay I'm making a platformer game, I have most of the code down, but I need help with some simple A.I...
So...there's an enemy, and what I want to happen is that when the main character gets close, he has 3 options, the enemy either walks closer, attacks, or blocks, and I want it to be random ...Can someone help me? (I have minimal knowledge of Arrays and Random, I checked the As:Main but it didn't help much...)
My about to make up a code from my expirience, but I've never used it before so it will probably need some tweaking but here we go:
pu this code on the enemy:
onClipEvent(load){
op = new Array("attack","block", "walk");
onClipEvent(enterFrame){
if(_root.guy._x<this._x){
//assuming this enemy is normally facing right
this._xscale = -100;
}
else{
this._xscale = 100;
}
if(Math.abs(this._x - _root.guy._x)<=50 and transition == true){
this.gotoAndPlay(op[Math.floor(Math.random
()*op.length)];
transition = false;
}
}
Now within the enemy movie clip make sure you have your attacking frame, your moving frame, and your blocking frame all labelled appropriately and at the end of the [insert action here] animation put in this code:
_parent.transition = true;
That should do it, but remember I never tested this so no promises.