Hey guys, I’ve been working on critter AI for Might is Right. I wanted something relatively simple, a behavior where a character would move around a fixed area and idle. Think bunny hopping around or a deer or something like that. Here’s what I got:
the AI is done using Behavior Tree, similar to what YUKA has. My implementation, of course, is in meep game engine.
The code is quite concise in the end. I did have to code a few custom behaviors though.
export function buildWanderingBehavior(
{
anchor = Vector3.zero,
distance = new NumericInterval(1, 2),
radius = 5,
axis = new BooleanVector3(true, false, true),
wanderAnimation = 'Walk',
idleAnimation = "Idle"
}
) {
return RepeatBehavior.from(
SequenceBehavior.from([
PickWanderPathBehavior.fromJSON({ radius: 5, anchor, distance, axis }),
StartAnimationBehavior.fromJSON({ name: wanderAnimation, repeatCount: Number.POSITIVE_INFINITY }),
ParallelBehavior.from([
new CheckPathEndBehavior(),
WaitForEventBehavior.fromJSON({ event: PathFollowerEventType.EndReached })
],
ParallelBehaviorPolicy.RequireOne,
ParallelBehaviorPolicy.RequireAll
),
StopAnimationBehavior.fromJSON({ name: wanderAnimation }),
StartAnimationBehavior.fromJSON({ name: idleAnimation, repeatCount: Number.POSITIVE_INFINITY }),
RandomDelayBehavior.from(2, 5),
StopAnimationBehavior.fromJSON({ name: idleAnimation }),
])
);
}