【问题标题】:c++ Sfml trying to move an object to the Mouse Location by a particular amount every framec ++ Sfml试图每帧将对象移动到鼠标位置特定数量
【发布时间】:2017-01-27 19:41:32
【问题描述】:

我有点被这个问题困扰

我创建了这个函数,但由于某种原因,我只能将对象移动到播放器的右侧。

如果我尝试将对象移动到播放器的左侧,则会向右移动。

这是我的方法:

int Speed = 8;
int x = Player_x - Mouse_x;
int y = Player_y - MOuse_y; 

float deg = atan(y / x);

float erg_x = Speed * cos(deg);
float erg_y = Speed * sin(deg);

erg_x/y 是我最后用来移动对象的数字。

请帮帮我:)

【问题讨论】:

    标签: c++ mouse move sfml


    【解决方案1】:

    正如here 所解释的,atan 仅适用于第一和第四象限。由于向左涉及第二象限,因此这是行不通的。

    因此,你会想要改变

    float deg = atan(y / x);
    

    float deg = atan2(y, x);
    

    【讨论】:

      猜你喜欢
      • 2011-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多