Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Time based grid movement  (Read 4471 times)

0 Members and 1 Guest are viewing this topic.

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Time based grid movement
« 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......

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Time based grid movement
« Reply #1 on: June 09, 2011, 02:16:03 am »
Doesn't seem to be any frame restrictions on the AI

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Time based grid movement
« Reply #2 on: June 09, 2011, 02:23:14 am »
Quote from: "David"
Doesn't seem to be any frame restrictions on the AI


can you elaborate a little more on it please!!!!

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Time based grid movement
« Reply #3 on: June 09, 2011, 02:39:13 am »
Quote from: "vicer1234"
Quote from: "David"
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

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Time based grid movement
« Reply #4 on: June 09, 2011, 02:51:59 am »
Quote from: "David"
Quote from: "vicer1234"
Quote from: "David"
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????

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Time based grid movement
« Reply #5 on: June 09, 2011, 03:06:22 am »
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?

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Time based grid movement
« Reply #6 on: June 09, 2011, 03:28:40 am »
Quote from: "David"
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

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Time based grid movement
« Reply #7 on: June 09, 2011, 03:39:58 am »
Quote from: "vicer1234"
Quote from: "David"
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)

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Time based grid movement
« Reply #8 on: June 09, 2011, 04:24:05 am »
Quote from: "David"
Quote from: "vicer1234"
Quote from: "David"
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??????

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Time based grid movement
« Reply #9 on: June 09, 2011, 05:13:38 am »
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

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Time based grid movement
« Reply #10 on: June 09, 2011, 06:35:27 am »
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
John Carmack can Divide by zer0.

Waterlimon

  • Newbie
  • *
  • Posts: 7
    • View Profile
Time based grid movement
« Reply #11 on: July 05, 2011, 05:33:39 pm »
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 >_>
This sententace makes me more unique. Too lazy to upload avatar. Nobody reads usernames.