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:
create tiny bounding box in center of each tile. "misses" collision.
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
Post a Comment