

If this range is not chosen correctly you may en up with the "doh! im in this (visually) cell but it says im in the future cell" problem, or the "my avatar is overlapping a wall".ĭont change the players cell until he is within a range (lets say 1/3 of the bounding sphere of the sprite) from the limits/borders of the cell that contains him. And allow the user to move inside that grid within a range of the cell's center without changing cells. To be able to achieve the desired effect, the sprites render position should be independent of where the entity represented by that sprite is located on the grid.
#Smoothmouse curve to fix grid movement update
It sounds like you update the players position (start of the animation) by changing the grid cell in which its contained. Polling constantly lets the player reverse directions at any time, and makes direction changes at intersections seem faster. This way the character doesn't have to wait to stop before moving on, and the player doesn't feel the game is unresponsive. If you want the character to stop anywhere, a reverse direction key should simply stop it in place.Ĭaching the key press allows the player to preemptively change directions as the character approaches an intersection. This all assumes that the character should continue moving, always, until it hits a wall and stops. Else if the input direction is opposite the current direction (it's in a hallway and the player wants to reverse), reverse the direction and then clear the key press.

If it's close to a direction changing node and can travel in the cached direction, change the direction and clear the cached direction. If it collides with a wall, stop the character. Also clear out the last key press to some invalid value.Įlse if the character is already moving, update the position of the character, checking for collision with a wall, or proximity to a direction changing node (intersection). If the character is idle in the center of a grid square, set it's velocity in the proper direction and upate the movement one step, unless there's a wall/collision object in the way. Poll the keyboard/joystick/whatever, and cache the last direction entered by the user. Have a Tick() or OnFrameEnter() function that does the following:
