2015-01-25 2 views
0

Enemy을 내 Player으로 옮기려고합니다.내 적을 내 플레이어로 이동시키기 C++

것은 내가 알고

  • 플레이어의 위치
  • Enemie` '위치

내가해야 할 일의 속도 :

  • 플레이어에게 방향을 알면 적을 얻습니다. o move

그래서 내가해야 할 일은 플레이어 위치에 따라 적의 위치를 ​​"정규화"하여 어디로 가야 하는지를 알고, 둘 다 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 

?

답변

6

normalize에 대한 사용자 정의는 사용하기 전까지는 오지 않습니다. 어느 Enemy::Move 전에 정의를 이동하거나 포함 한 후 파일의 맨 위에 함수 선언을 넣어 :

Vector2f normalize(const Vector2f& source); 

이 같은 행동의 small example입니다.