Be a Supporter!

Insect AI

  • 387 Views
  • 4 Replies
New Topic Respond to this Topic
The-Mercenary
The-Mercenary
  • Member since: Jan. 22, 2003
  • Offline.
Forum Stats
Member
Level 18
Musician
Insect AI 2009-02-21 16:27:16 Reply

anyone know any simple code that could simulate a simple insect AI? Its just for something in the background of my game, and animating it doesn't give me much variety.

Blue-Devil23
Blue-Devil23
  • Member since: Sep. 4, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to Insect AI 2009-02-21 16:32:51 Reply

Try this maybe?

The-Mercenary
The-Mercenary
  • Member since: Jan. 22, 2003
  • Offline.
Forum Stats
Member
Level 18
Musician
Response to Insect AI 2009-02-21 16:37:49 Reply

At 2/21/09 04:32 PM, Blue-Devil23 wrote: Try this maybe?

thanks :) Not exactly what I needed, but it'll work.

The-Mercenary
The-Mercenary
  • Member since: Jan. 22, 2003
  • Offline.
Forum Stats
Member
Level 18
Musician
Response to Insect AI 2009-02-21 17:04:37 Reply

Actually, I just figured out a really simple way of doing this.

function moveInsect(nameOfIns, origX, origY, speedIns)
{
if (nameOfIns._x<origX-100) {
nameOfIns._rotation = random(180);
speedIns += -10+random(25);
} else if (nameOfIns._x>origX+100) {
speedIns += -10+random(25);
nameOfIns._rotation = random(180)*-1;
} else if (nameOfIns._y<origY-100) {
nameOfIns._rotation = 90+random(180);
speedIns += -10+random(25);
} else if (nameOfIns._y>origY+100) {
nameOfIns._rotation = (270+random(180));
speedIns += -10+random(25);
}
if (speedIns>40) {
speedIns = 15;
}
nameOfIns._x += speedIns*Math.sin(nameOfIns._rotation*Ma th.PI/180);
nameOfIns._y += -speedIns*Math.cos(nameOfIns._rotation*M ath.PI/180);
}

this way, all you I do is make the speed rotation random and it does the rest. The link you gave me was packed with too much code for something I just wanted to be in the background. But Thanks :)

pradvan
pradvan
  • Member since: Feb. 21, 2009
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Insect AI 2009-02-21 18:53:02 Reply

At 2/21/09 05:04 PM, The-Mercenary wrote: The link you gave me was packed with too much code for something I just wanted to be in the background

That's an older version of the enemy ai script i wrote. Here is the newer, optimized version: http://www.freeactionscript.com/2009/01/
random-movement-random-direction-change/

-PR