SFML community forums

General => Feature requests => Topic started by: MrOnlineCoder on October 01, 2016, 08:17:21 pm

Title: moveTo method for Vector2
Post by: MrOnlineCoder on October 01, 2016, 08:17:21 pm
Hello. Very often in games there is need to move object A to object B smoothly. Can this function be implemented in SFML? Something like this:
pointA.moveTo(pointB, 1f);
//=> pointA is now closer to pointB by 1 pixel
 
Title: Re: moveTo method for Vector2
Post by: Laurent on October 01, 2016, 08:35:10 pm
It's not so common to move by one pixel. And your solution wastes CPU cycles because you recompute (pointB - pointA) for every pixel to move.

What is more common is to store a velocity and compute the move with the elapsed time.

pointA += velocity * elapsed.asSeconds();
Title: Re: moveTo method for Vector2
Post by: MrOnlineCoder on October 01, 2016, 09:23:45 pm
1 pixel I used just for example  ;)
Title: Re: moveTo method for Vector2
Post by: Hapax on October 04, 2016, 05:58:41 pm
You can interpolate the two positions. To move a specific amount, you could multiply by a unit vector of the path.