Forum Topic: Insect AI

(101 views • 4 replies)

This topic is 1 page long.

<< < > >>
None

The-Mercenary

Reply To Post Reply & Quote

Posted at: 2/21/09 04:27 PM

The-Mercenary EVIL LEVEL 17

Sign-Up: 01/22/03

Posts: 2,623

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.


None

Blue-Devil23

Reply To Post Reply & Quote

Posted at: 2/21/09 04:32 PM

Blue-Devil23 EVIL LEVEL 13

Sign-Up: 09/04/05

Posts: 55

Try this maybe?


None

The-Mercenary

Reply To Post Reply & Quote

Posted at: 2/21/09 04:37 PM

The-Mercenary EVIL LEVEL 17

Sign-Up: 01/22/03

Posts: 2,623

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

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


None

The-Mercenary

Reply To Post Reply & Quote

Posted at: 2/21/09 05:04 PM

The-Mercenary EVIL LEVEL 17

Sign-Up: 01/22/03

Posts: 2,623

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 :)


Blushing

pradvan

Reply To Post Reply & Quote

Posted at: 2/21/09 06:53 PM

pradvan NEUTRAL LEVEL 01

Sign-Up: 02/21/09

Posts: 5

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


All times are Eastern Standard Time (GMT -5) | Current Time: 06:56 PM

<< 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!