in 2d space I've been using Math.atan2() to get the angle (from -pi to pi) between 2 points, then multiply the x value by Math.sin(direction) and the y value by Math.sin(direction). Works like a charm, also for running away from something just use direction + pi. Ahhhh polar coordinates.

in 2d space I've been using Math.atan2() to get the angle (from -pi to pi) between 2 points, then multiply the x value by Math.sin(direction) and the y value by Math.sin(direction). Works like a charm, also for running away from something just use direction + pi. Ahhhh polar coordinates.

Angles are usually not needed. TheAgent method is fastest and simplest. But there is problem if distance = 0 so that need to be taken care of.

I've been considering implementing a concept similar to IR object detection:

1. Scan 180 degree area (radius is distance from entity to player) for obstacles.2. Record where obstacles are and how far away they are, as well as where open spaces are that can be moved through.3. Path calculation can be based on open space > far object > near object > very near obstacle (can't move here)

The question is how to write that in code and how to actually lay out the path. Should it be determined in segments? One segment=pace perhaps?

If the purpose of the AI is to close to one (or many) Player-positions, then it needs 3 parts:-recognize when to move (like seeing player)and where to (playerposition, or hidingspot)-plan how to move (build a pathfinding-path, waypoints or just find a general direction)-pursue the move according to plan and dynamic obstacles. (Step by step following the path, stop at and avoid dynamic obstacles)

Each part can be developed in a seperate step.Where each generates the input of another part.

Once this simple "see-follow" works out, you might want to think about a "top level" AI, like a finite statemachine or "general" or scriptthat controls the AI in more complex situations.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org