So I have a class for my NPC, and I have some code to manually track the players movement by making the npc slightly rotate his head. So it’s a little rough but I might be using the wrong event type. It seems like the players position is never updated.
void AIMelee::LookAtPlayer(StringHash eventType, VariantMap& eventData)
{
head = node_->GetChild("head", true);
Node* player = scene_->GetChild("Player", true);
Vector3 worldPos = head->GetWorldPosition();
Vector3 headWorldTarget = head->GetWorldPosition() + worldPos * Vector3(player->GetWorldPosition().x_, player->GetWorldPosition().y_, 0.5f);
head->LookAt(headWorldTarget, Vector3::RIGHT);
// debug lines
DebugRenderer *dbgRenderer = scene_->GetComponent<DebugRenderer>();
dbgRenderer->AddLine(headWorldTarget, head->GetWorldPosition(), Color::YELLOW);
}
The event is:
SubscribeToEvent(E_POSTUPDATE, URHO3D_HANDLER(AIMelee, LookAtPlayer));