Look around behaviour

I am currently working on Agent framework that is integrated with jMonkey, uses Neural Network for reasoning and should be relatively simple to use without programmer needing to learn NN. First versions will be mostly for FPS genre. Now, I am having problems with implementing how NPCs observe their surroundings. I have never participated in developing game in jMonkey and everything that I know about game developing in jMonkey is what I have read in documentation and in forums. As I see it, correct me if I am wrong, everybody saves their game environment data in rootNode. If this is correct, I must ask if there is any data structure except rootNode that have information for environment that is better for terrain processing and also is there any way to determine, if NPC is looking at some game object or not. Is there anything like this, I really don’t want to program this if I really don’t need to.

I don’t think there’s any other data structure that will help you.

From the scene graph, it’s fairly easy to determine whether an NPC can see a particular point on a geometry – I plan to implement this in my own game soon for use in AI.

Determining whether any point on a geometry is visible would take more work – I’d be tempted to give each NPC its own camera and viewport for that.

Well one way is to sue the scenegraph, another way is to use completly own data structures.

If you want it to be generic, code against a interface that must be proveded for the constructor or similar, that has all stuff you need.

Eg
[java]
interface IAiConnector{
IObjectProxy getListOfVisibleObjects()
Vector3f getLocation();
}
interface IObjectProxy{
Vector3f getObjectLocation()
EObjectType getType()
}
enum EObjectType{
DOOR,MEDIKIT,WEAPON,ENEMY
}
[/java]

and make everything abstracted from the jme scenegraph.

Why this extra piping trough interfaces?
Well suddenly your ai is no longer depended on jme and a specific use case.
Also it no longer requires to use the rootnode in a specific way. (As everyone can write kinda an adapter for their logic to the required interfaces)

My gamelogic for example resides completly inside an Entity System, and the Jme side is purly for visualisation. In fact on the Server there is not even a scenegraph, only a physicsspace.

Also this would allow me to let my normal medicconsole (think hl2) appear as a medikit for the bot, a few additional checks on the console, and it could heal the bot if it stands there.

Building my own data structure for environment and preprocessing terrain sounds like best solution for now. I’ll have to think what structure is best for my needs. Thanks a lot. :smiley:

1 Like

I have built everything I need for basic agent framework, except this one method for looking behaviour (lookable). Problem now is if some 3D point (Vector3f) can be seen by some other point “observer” (also Vector3f). Observer has Quaternion which represents in which direction is NPC looking, and some angle (float) that represents width. For starters, I wanted to test it with bots only, turning left and right, so I could implement lookable as problem “is point inside of triangle”, but after much debugging I see that not only Y coordinate changes when rotating, but also W coordinate. In documentation I couldn’t find anything about W and how it changes. Any suggestions how I can implement method lookable?

You can convert a quaternion into a direction vector using getRotationColumn() or mult(). For instance:
[java]
Vector3f direction = rotation.mult(baseDirection);
[/java]
You can calculate the direction vector from one point to another using subtract() and normalize(). For instance:
[java]
Vector3f direction2 = point1.subtract(point2).normalizeLocal();
[/java]
You can calculate the angle between two direction vectors using angleBetween(). For instance:
[java]
float angle = direction.angleBetween(direction2);
[/java]

You can learn about vectors and quaternions by reviewing the online tutorial:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

I hope that helps

Thanks. It works really good. :smiley:

1 Like