Page 1 of 1

AI-induced migraines ahoy!

Posted: Tue May 29, 2007 10:58 pm
by thirdeye77
Ohhhh....my head hurts. The last 2 days have been spent trying to get an apparently straightforward AI to work:

Code: Select all

ENTER = ("scanForNearestShipWithRole: shipwreck");
"TARGET_FOUND" = (setTargetToFoundTarget, setDestinationToTarget, "setSpeedFactorTo: 0.3", "setDesiredRangeTo: 350.0", performFlyToRangeFromDestination);
"NOTHING_FOUND" = ("setStateTo: WANDER");
"DESIRED_RANGE_ACHIEVED" = (becomeExplosion, "setStateTo: SCHOOL");
It should be simple - the ship scans for a "shipwreck" and flies towards it until it reaches a range of 350m and then explodes (for testing purposes). So how come the ship explodes immediately even tho its 10km away from the destination????

I know its picking up the "shipwreck" and will fly towards it correctly without the "DESIRED_RANGE_ACHIEVED" line.

I've also tried using the checkCourseToDestination method as used in other AIs but it seems the desired range achieved message is always received immediately, regardless of the actual range to destination. Having played around with every combination of methods I can think of I'm now kinda stumped :?

Posted: Wed May 30, 2007 6:32 am
by Arexack_Heretic
first thing I notice is the statechange AFTER becomeExplosion.

But your AI looks sound otherwise,
maybe a previous method messaging "range achieved",
we need to see the whole AI.

Try using a statechange to state "EXPLODE" instead of the immediate method.

Posted: Wed May 30, 2007 10:43 am
by Arexack_Heretic
There is a debug way to have the nearby objects dump their AI states into the logfile...I don't recall how anymore.
I used a cumbersome method of commsmessages a whileback to keep track of the AI while in-game.

One thing you may try is:

Code: Select all

"NOTHING_FOUND" = ("commsMessage: No target in range");
UPDATE = ("commsMessage: scanning again", "scanForShipWithRole: wreckage");

Posted: Wed May 30, 2007 7:01 pm
by thirdeye77
The becomeExplosion was only put in there to make it really obvious when the statechange was coming into play. It won't be there in the finished version.

Desired range achieved seemed to be flagged as soon as scanForShipWithRole was used, regardless of whether a desired range had been set or not, or if the range was set to 0 or 100000.

I've now managed to get it to work by just sticking the Desired Range Achieved flag in a separate state:

Code: Select all

"CHECK_RANGE" = { ENTER = (); "DESIRED_RANGE_ACHIEVED" = ("setStateTo: SCHOOL"); };
and then switching to this state after the performFlyToRangeFromDestination:

Code: Select all

"TARGET_FOUND" = (setTargetToFoundTarget, setDestinationToTarget, "setSpeedFactorTo: 1.0", "setDesiredRangeTo: 500.0", performFlyToRangeFromDestination, "setStateTo: CHECK_RANGE");
It seems to work now, no idea why!

Thanks for the input Arexack_Heretic :D
Glad to know I'm not the only one littering comms messages throughout the AI. Must remember to take them out in the finished product :roll:

Posted: Sat Jun 02, 2007 7:43 pm
by Commander McLane
thirdeye77 wrote:
Glad to know I'm not the only one littering comms messages throughout the AI. Must remember to take them out in the finished product :roll:
I'm doing it all the time. It seems the best way for checking out AIs.

Hmmm, putting things in seperate states could be a way of dealing with a problem I had in an AI. Should try it out...

Posted: Sat Jun 02, 2007 8:49 pm
by Arexack_Heretic
I had a similar problem with the orb-missile...couldnt just launch it, but spawning it it didn't seem able to lock on to a target.
It just exploded, I used performFlyToRange as well.