#2D Rectangle moving diagonally when clicking bug

5 messages · Page 1 of 1 (latest)

sour otter
#

So I'm using Graphics2D in order to create a simple game where I have the world divided into a grid, and when I click somewhere in the world, it gets the players current position and the position I clicked at which is mouseClickPosition.x / tileSize.
it then uses that in order to calculate the shortest path within the grid by using the BFS algorithm.

The issue has nothing to do with the algorithm itself, it's more so when I'm actually moving the rectangle from point A to point B diagonally.
So moving diagonally is fine, but if I'm trying to walk diagonally when there is a non walkable tile, I want it to walk around.. And it does!
However, if I click fast enough, it's going to slide across because "it thinks" that it's at a certain position due to the fact that the top left corner is at that position is within that range.

neat pebbleBOT
#

Hey, @sour otter!
Please remember to /close this post once your question has been answered!

sour otter
#

So I'm rendering the rectangle 144 times per second and if it has to move it's going to do rectangleX/Y += 3 every update until it reaches the tile I clicked