r/pythonarcade • • Aug 24 '19
Is there a simple destination-based movement?
Like if I have starting coordinates and destination coordinates, and I want my sprite to automatically stop at the destination without headaches.
3
Upvotes
View all comments
Show parent comment
4
u/[deleted] Aug 25 '19 edited Aug 25 '19
Unfortunately, if you were looking for some form of
sprite.move_smoothly_until_you_reach_this_point(dest, speed)function that you could just call once and it would take care of everything for you, such a thing doesn't exist.The closest you can get is to implement it yourself using a method that sets a destination and a subroutine of
updatethat does the actual work, which still involves keeping track of the destination and moving it each frame (pseudocode follows):There's no real way to stop the sprite from going too far without using a conditional statement that simply snaps the sprite to the destination coordinates when the distance left to the destination is less than the distance advanced. You just have to use that conditional here.