My game is a top down 2d twin stick hack n slash.
I have an enemy object that I want to continuously move towards the player object. I figured a simplified version of Heuristic pathfinding would be the best way to do this whereby every time enemy.update() is called the following happens:
- Create a point for each of the cardinal directions (N, NE, E...etc) around the enemy object at a distance of one Step(predefined movement amount in pixels) away from the enemy object
- Loop through these and check which point would make the enemy object closer to the PC
- Move the enemy object in that direction
My thoughts on how to do this are to create an ArrayList containing the possible movement directions then subtract the elements from the player position in turn to give the distance from the player, then select the smallest distance as the direction the object moves.
In terms of implementation I am not sure whether to use points or vectors. I have done a little research and found nothing that implies I can use mathematical operators on points, is this possible? And if not should I use vectors and can someone point me to a resource on how to implement this?
Thanks in advance