c++ - Correct movement to exact position when using floats -


in pathfinding game, have following code:

void dot::move( tile *tiles[], float timestep ) {         mvelx = (points[currentpoint].x * tile_width)                 + (tile_width / 2 - dot_width / 2)- mbox.x;         mvely = (points[currentpoint].y * tile_height)                 + (tile_height / 2 - dot_height / 2) - mbox.y;          mbox.x += mvelx * dot_vel * timestep;         mbox.y += mvely * dot_vel * timestep; } 

mbox position. points refers solution of pathfinder. dot has no problem moving tile tile, it's "off center".

http://i.stack.imgur.com/6jszz.png

some solutions i've considered:

  1. create tiny bounding box in center of each tile. "misses" collision.

  2. use epsilon value. unfortunately leads trial , error , imprecise results.

the other issue easing (for example adding friction). dot "slide" way longer needs until reaches center. results in awkward movements.

if can make circle's "position" center of circle instead of edge, should fine. if keeping right edge "position", when center or whatever, should offset right radius circle.

i have answered question best of ability, hard give complete, accurate, , correct answer code provided.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -