Jump to content
  • Advertisement
Sign in to follow this  

Ai movement in grid

This topic is 2572 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!