• Create Account

### #Actualsega16

Posted 29 September 2012 - 09:33 PM

Hello everyone. I am having some issues with my path following algorithm the enemys are supposed to follow a path that I set in the level editor. I know the path is being correctly set I can verify that. The issue is that lets say the enemy is on pixel 64 and each tile is 64 pixels the enemy is moving to the left the next tile over is to move down. The enemy moves left by lets say 2 pixels. As soon as it moves to pixel 62 the enemy will move down. I am fully aware of how integer math works 62/64=0. At first I was able to use modules and just do if (x%64 == 0 && y%64 == ) then change the direction but I was limited to speeds that are a factor of 64 and I could not work with that maily becuase my code varies the enemy speed based on frames per second and I would like more control over speed. Here is the code I used to get the direction I removed the module checks after I added the code to move based on pixels per millosecond instead of pixels per frame As the enemys would go off the path even worse due to the fact that the direction would never change.
direction=path[((x>>bloon_fract_bits)/tile_size_px)+(((y>>bloon_fract_bits)/tile_size_px)*11)];

Also just to give a heads up the bitshifts are because I am using fixed point math for the enemy speed and the array path is uchar array that is 88 bytes my level is 11x8 tiles and the tiles are 64 pixels each
Here are some pictures
The correct path in the level editor:
Click on image for full size on my computer it resizes the pictures ~99% and makes them look blurry it is not your vision.

The incorrect path being taken

If anybody has a good algorithm to correctly follow the path it would help me alot thank you for reading this

### #3sega16

Posted 29 September 2012 - 09:27 PM

Hello everyone. I am having some issues with my path following algorithm the enemys are supposed to follow a path that I set in the level editor. I know the path is being correctly set I can verify that. The issue is that lets say the enemy is on pixel 64 and each tile is 64 pixels the enemy is moving to the left the next tile over is to move down. The enemy moves left by lets say 2 pixels. As soon as it moves to pixel 62 the enemy will move down. I am fully aware of how integer math works 62/64=0. At first I was able to use modules and just do if (x%64 == 0 && y%64 == ) then change the direction but I was limited to speeds that are a factor of 64 and I could not work with that maily becuase my code varies the enemy speed based on frames per second and I would like more control over speed. Here is the code I used to get the direction I removed the module checks after I added the code to move based on pixels per millosecond instead of pixels per frame As the enemys would go off the path even worse due to the fact that the direction would never change.
direction=path[((x>>bloon_fract_bits)/tile_size_px)+(((y>>bloon_fract_bits)/tile_size_px)*11)];

Also just to give a heads up the bitshifts are because I am using fixed point math for the enemy speed and the array path is uchar array that is 88 bytes my level is 11x8 tiles and the tiles are 64 pixels each
Here are some pictures
The correct path in the level editor:
Click on image for full size on my computer it resizes the pictures ~99% and makes them look blurry it is not your vision.

The incorrect path being taken

If anybody has a good algorithm to correctly follow the path it would help me alot thank you for reading this

### #2sega16

Posted 29 September 2012 - 09:25 PM

Hello everyone. I am having some issues with my path following algorithm the enemys are supposed to follow a path that I set in the level editor. I know the path is being correctly set I can verify that. The issue is that lets say the enemy is on pixel 64 and each tile is 64 pixels the enemy is moving to the left the next tile over is to move down. The enemy moves left by lets say 2 pixels. As soon as it moves to pixel 62 the enemy will move down. I am fully aware of how integer math works 62/64=0. At first I was able to use modules and just do if (x%64 == 0 && y%64 == ) then change the direction but I was limited to speeds that are a factor of 64 and I could not work with that maily becuase my code varies the enemy speed based on frames per second and I would like more control over speed. Here is the code I used to get the direction I removed the module checks after I added the code to move based on pixels per millosecond instead of pixels per frame As the enemys would go off the path even worse due to the fact that the direction would never change.
direction=path[((x>>bloon_fract_bits)/tile_size_px)+(((y>>bloon_fract_bits)/tile_size_px)*11)];

Also just to give a heads up the bitshifts are because I am using fixed point math for the enemy speed and the array path is uchar array that is 88 bytes my level is 11x8 tiles and the tiles are 64 pixels each
Here are some pictures
The correct path in the level editor:

The incorrect path being taken

If anybody has a good algorithm to correctly follow the path it would help me alot thank you for reading this

### #1sega16

Posted 29 September 2012 - 09:22 PM

Hello everyone. I am having some issues with my path following algorithm the enemys are supposed to follow a path that I set in the level editor. I know the path is being correctly set I can verify that. The issue is that lets say the enemy is on pixel 64 and each tile is 64 pixels the enemy is moving to the left the next tile over is to move down. The enemy moves left by lets say 2 pixels. As soon as it moves to pixel 62 the enemy will move down. I am fully aware of how integer math works 62/64=0. At first I was able to use modules and just do if (x%64 == 0 && y%64 == ) then change the direction but I was limited to speeds that are a factor of 64 and I could not work with that maily becuase my code varies the enemy speed per frame based on the frames per second. Here is the code I used to get the direction I removed the module checks after I added the code to move based on pixels per millosecond instead of pixels per frame.
direction=path[((x>>bloon_fract_bits)/tile_size_px)+(((y>>bloon_fract_bits)/tile_size_px)*11)];

Also just to give a heads up the bitshifts are because I am using fixed point math for the enemy speed and path is uchar array that is 88 bytes my level is 11x8 tiles the tiles are 64 pixels each
Here are some pictures
The correct path in the level editor:

The incorrect path being taken

If anybody has a good algorithm to correctly follow the path it would help me alot thank you for reading this

PARTNERS