libgdx / gdx-ai

Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines
Apache License 2.0
1.18k stars 241 forks source link

Calculate distance between steerables in a 2D wrapped around environment #40

Open implicit-invocation opened 8 years ago

implicit-invocation commented 8 years ago

Imagine our characters is moving on the surface of a sphere. So there will be 2 ways to calculate distance between them. But all of gdx-ai behaviors use owner.getPosition() to calculate distance.

I think Steerable interface should have getDistance(point:Vector2):float getDistanceSq(point:Vector2):float method and behaviors will use them to decide how to seek, evade, flee...

davebaol commented 8 years ago

Hmmm... Shouldn't something like

toTarget.set(target.getPosition()).sub(owner.getPosition());

be affected too?

implicit-invocation commented 8 years ago

and getDistance(agent:Steerable):float, getDistanceSq(agent:Steerable):float or getToTargetVector(agent:Steerable, agent:Steerable):Vector2, maybe

davebaol commented 8 years ago

At a first glance I'd say that toTarget should be an instance of a class that extends Vector2 and overrides the appropriate methods. But currently there's no way to set vectors internally used by behaviors.