精灵在目标点旋转

Sprite rotates in the destination point

我正在尝试对我的 sprite 进行点击控制。基本上一切都很好,但是当 sprite 到达目的地点时会出现奇怪的伪影。看起来它不断地旋转 180 度,一遍又一遍。

和正常状态做对比。

我尝试使用此功能避免它:

sf::Vector2f GetDirection(const sf::Vector2f& start, const sf::Vector2f& destination) {
    sf::Vector2f dir = destination - start;
    if (GetLength(dir) <= 0.1) {
        return sf::Vector2f(0.0f, 0.0f);
    }
    return Normalize(dir);
}

但条件很少为真。完整代码 is here.

我做错了什么?

你的问题是没办法"break".

您将达到 300/300。你超出了你的目标。到你了。你回去吧。你超出了你的目标。冲洗并重复。

您缺少一项检查,如果您当前的速度超过达到目标所需的速度,则您应该只使用必要的速度。不多了。

你的检查很好。但它会检查您与目标的距离是否小于十分之一像素。也许你应该检查不那么详细。一个像素就足够了。替换

if (GetLength(dir) <= 0.1) {

if (GetLength(dir) <= 1.0) {

它会起作用。