我正试图让我Enemy
移动到我的Player
.
我知道的事情:
- 球员的位置
- 敌人的位置
- 敌人的速度
我需要做的事情:
- 知道玩家的方向,让敌人移动
所以我认为我需要做的是根据玩家的位置“标准化”敌人的位置,这样我就知道该去哪里,并且两者都有一个基于Vector2f
.
这是我在敌人中的代码:
void Enemy::Move()
{
//cout << "Move" << endl;
// Make movement
Vector2f playerPosition = EntityManager::Instance().player.GetPosition();
Vector2f thisPosition;
thisPosition.x = xPos;
thisPosition.y = yPos;
//Vector2f direction = normalize(playerPosition - thisPosition);
speed = 5;
//EntityManager::Instance().enemy.enemyVisual.move(speed * direction);
}
Vector2f normalize(const Vector2f& source)
{
float length = sqrt((source.x * source.x) + (source.y * source.y));
if (length != 0)
return Vector2f(source.x / length, source.y / length);
else
return source;
}
错误是:
'normalize': identifier not found
我究竟做错了什么?