Sign in to follow this  
vicer1234

Ai movement in grid

Recommended Posts

vicer1234    115
Hi,
I am trying to make a grid based game. I have a 100x100 grid, where i can control my player to move across one slot using key.
The player movement is working well and I can move across the grid ONE FRAME AT A TIME.

The main problem is with AI player movement. I am using A* algorithm to get the path for the AI component. What i am doing at present is:

1) I give the AI player position and the goal position to the A* algorithm and generate the path. ( this calculation is Inside the game Update function )
The output of the A* algorithm is a string which gives the grid locations.
2) Then inside the draw function when I use a for loop to draw for each grid location, the AI player reaches the goal in split of a second..just within one frame




what i want is that the ai player should move slowly towards the goal ...so that there is a perfect competition between the user and ai to reach the goal.

How to control the movement of AI player so that its playable enough?????


All suggestions are welcome......

Share this post


Link to post
Share on other sites
Kian    239
How are you handling frames? A regular game, to look smooth and feel responsive, goes at 30 to 60 frames per second. It sounds as though your AI player goes at that same speed, without waiting.

One solution is to go from one square per frame, to one square per second. Another is to force the AI player to update it's position only when the human player does. I'm guessing you discard the AI's position after you draw it. You'd have to retain it, and wait for the human player to move before advancing the AI.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this