What is the easiest way to implement DPad style movement (No diagonal) for AI without using and A* algorithm? I thought about having the enemy catch up to the player in the Y axis first then the X axis (or vice versa) but then it would be too easy to evade the enemy. If it matters I'm doing this in Objective-C using Cocos2d. Any input would be appreciated.
|
For Orthogonal movement, you can choose randomly between the two directions you need to go.
The red player and blue enemy are in the world. They are separated by 2x and 3y or (2,3). So we know we need to move in both the X plus direction and the Y plus direction. So we choose randomly between the two. Say we choose the X plus direction, now they're separated by (1,3). Now say the random choice again chooses X plus direction. Now they're separated by (0,3). Now the only choice is to move in the Y plus direction. Otherwise, move in the longest direction first, then the shortest. If you're worried about the player being able to too easily avoid the enemy make the enemy move slightly more often than the player. Say 1.1 moves per the player's 1 move. |
|||||||||||||
|
