Hi, I'm currently trying to implement game play where a player and an enemy are snapped to the grid and the enemy will constantly find a path to the player (even while the player is moving). The entities can only move in the directions left, right, up, and down.
1.) My first approach was to implement path finding using Breadth-first search (no thread).
The game lags (of course) because the computer is having to do too much work.
2.) My second approach was to implement path finding still using Breadth-first search except this time using a thread.
Using a non-detached thread, the game doesn't lag anymore, however, the enemy freezes at times (I assume from trying to calculate the constant movement).
I choose to find a new path only when the enemy is snapped to the grid and when the last found unused path is retrieved by the enemy controller.
Any ideas on another approach to this problem? I'm only going to have one enemy which constantly calculates a path to the player. I'll try to post some code later today.
I hope someone will be able to assist me!
Update (3/5/2016 8:12 PM):
I was able to fix the problem. It was a logic error, fortunately. I was checking for a path based on the player's (x,y) position (which can be a float value) instead of integer values divisible by the grid's (width, height).