Skip to content

Entity Relationships #199

@NeusFear

Description

@NeusFear

I love the simplicity of the library, and plan to replace my own slow ECS implementation in my custom game engine with this, but a feature that I find to be missing is entity relationships. An example of how this could work is:

entity1.addRelationship(entity2, "hates");
entity1.addRelationship(entity3, "loves");

// then in a system you could do
Runnable system = () -> {
    //finds entities that entity1 hates
    hello.findEntitiesWithRelationship(entity1, "hates")
            //filter those entities to ones with position and velocity components
            .withAlso(Position.class, Velocity.class)
            // stream the results
            .stream().forEach(result -> {
                ...
            });
};

The benefit of such a system in a game are limitless, but here is a couple examples:

  1. A group of players attack a enemy, we can add the "underAttacckBy" relationship to the enemy for each of the attacking players, then a system can loop through those players to attack the closest one, or the one with the least health, etc.
  2. A player uses a fireball spell in the middle of a town center, you can get all entities in a radius around the player and put a "fears" relationship to the player to each of the surrounding NCPs and they will remember that they saw that player do something scary a while ago.

I am sure that there are more use cases, and that there is a better way to handle system results to keep your query optimizations working, but wanted your thoughts on such a feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions