Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++11 精灵在目标点旋转_C++11_Sfml - Fatal编程技术网

C++11 精灵在目标点旋转

C++11 精灵在目标点旋转,c++11,sfml,C++11,Sfml,我正在尝试对我的精灵实现点击控制。基本上一切都很好,但当精灵到达目的地时,会出现奇怪的伪影。看起来它不断地旋转180度 与正常状态进行比较。 我尝试使用此函数来避免它: sf::Vector2f GetDirection(const sf::Vector2f& start, const sf::Vector2f& destination) { sf::Vector2f dir = destination - start; if (GetLength(dir) &

我正在尝试对我的精灵实现点击控制。基本上一切都很好,但当精灵到达目的地时,会出现奇怪的伪影。看起来它不断地旋转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);
}
sf::Vector2f GetDirection(常量sf::Vector2f&start,常量sf::Vector2f&destination){
sf::Vector2f dir=目的地-开始;

如果(GetLength(dir)您的问题是无法“中断”

你将达到300/300。你超出了你的目标。你转身。你返回。你超出了你的目标。冲洗并重复

如果你的当前速度超过了达到目标所需的速度,你就应该使用所需的速度,而不是更多

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

if (GetLength(dir) <= 0.1) {
if(GetLength(dir)
if (GetLength(dir) <= 1.0) {