SFML community forums
Help => General => Topic started by: vicer1234 on June 09, 2011, 02:05:12 am
-
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......
-
Doesn't seem to be any frame restrictions on the AI
-
Doesn't seem to be any frame restrictions on the AI
can you elaborate a little more on it please!!!!
-
Doesn't seem to be any frame restrictions on the AI
can you elaborate a little more on it please!!!!
I'm pretty sure you're implementing GetElapsedTime() in the movement of your main character. But for some reason, it doesn't show up at all for the AI
-
Doesn't seem to be any frame restrictions on the AI
can you elaborate a little more on it please!!!!
I'm pretty sure you're implementing GetElapsedTime() in the movement of your main character. But for some reason, it doesn't show up at all for the AI
you mean multiplying the position of ai with the elapsed time?
mp_AiSprite->Move((float) x * 16 * elapsedTime, (float)y * 16 * elapsedTime)
but this makes the position movement incorrect...since (x,y) indicates the grid position in 0,1,2,3....etc format and '16' is the sprite size.so multiplying them i get the pixel position.
if i multiply the time factor then the sprite moves in wrong position as it gets displaced incorrectly.
Is it what you meant to say????
-
Sorry, maybe I'm not making this clear
What do you mean one frame at a time, anyways? Like does the main player moves from one tile to another smoothly or does he sorta "teleport" to the tile he moves to?
-
Sorry, maybe I'm not making this clear
What do you mean one frame at a time, anyways? Like does the main player moves from one tile to another smoothly or does he sorta "teleport" to the tile he moves to?
it moves smoothly
-
Sorry, maybe I'm not making this clear
What do you mean one frame at a time, anyways? Like does the main player moves from one tile to another smoothly or does he sorta "teleport" to the tile he moves to?
it moves smoothly
Ah,
So you would move the AI to its destined tiles based just like you would with your player by calculating the direction the AI has to take.
Or you can use something similar to the tween class used in Flash and see what's there (It's doing a smooth movment from one place to another using pure code)
-
Sorry, maybe I'm not making this clear
What do you mean one frame at a time, anyways? Like does the main player moves from one tile to another smoothly or does he sorta "teleport" to the tile he moves to?
it moves smoothly
Ah,
So you would move the AI to its destined tiles based just like you would with your player by calculating the direction the AI has to take.
Or you can use something similar to the tween class used in Flash and see what's there (It's doing a smooth movment from one place to another using pure code)
direction...?? suppose the grid location returned is ( 1,2) its value in pixel will be (1*16, 2*16) how can i get direction from it??????
-
The best way is to get the location of the original tile, then get the location of the tile it's going to move to. Calculate how you're going to make movement between the two, and continue until the AI reaches its destination.
Ignore the direction part. I've got a better idea
-
The problem i think is this line
mp_StartSprite->Move
you want to use the SetPosition so it just snaps the the position you give it, another problem is this is in a nested for loop, so this might get called all several times before you get to see it, (sounds like your problem)
perhaps use a break after the PATH check but without seeing all of your code its hard to know
-
Do something liek this:
Have something to keep track of the current location in the path string.
Then, move the AI to the next location, and have some timer thing. each frame check the timer thing to see if some time is passed, and if it is, move the AI to the next location and so on. Currently youre just moving it thru all the positions in the single frame or something >_>