slapin
Hi, all!
How would you implement “closest visible item” query for NPC in Urho?
Hi, all!
How would you implement “closest visible item” query for NPC in Urho?
template <class T> T* GetNearestInstanceOf(Vector3 location)
{
T* nearest{ nullptr };
float nearestDistance{ M_INFINITY };
PODVector<T*> components{};
world.scene->GetDerivedComponents<T>(components, true);
for (T* c : components) {
Node* node{ static_cast<Component*>(c)->GetNode() };
float distance{ (location - node->GetWorldPosition()).LengthSquared() };
if (distance < nearestDistance) {
nearest = c;
nearestDistance = distance;
}
}
return nearest;
}
That’s absurdly useful for my game. Thank you so much sir.
Some more thing about influence map.
Imagine an NPC. He have
So the role for influence map is to accelerate all these considerations for many NPCs.
Which is wat I want to eventually get to. as I see, there are a few data sets there.
Any ideas on where to look for inspiration and code?
Thanks!
Since you don’t need the actual distance value for the comparison, you can improve the performance by using LengthSquared() instead.
Ah, thanks. Saves a Sqrt() I guess?