Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closest Target Scene with KD Tree Algorithm not always finds the nearest target #275

Open
houshuo opened this issue Oct 24, 2023 · 1 comment

Comments

@houshuo
Copy link

houshuo commented Oct 24, 2023

Apprently, in the screenshot below, the green boxes find wrong nearest target. With None and Simple algorithms, such error won't happen.
image

@cihanozcelik
Copy link

Hello,

I've noticed a potential issue in the TargetingSystem.cs file on line 141 (TargetingSystem.cs). The GetEntriesInRangeWithHeap method is called with unfilteredChunkIndex as the first parameter. This parameter is intended to be an entity index within kdQuery, to ensure the algorithm does not find the entity that is performing the search. However, in this sample, the seeker entities are not included in kdQuery, so there is no need to skip any entity. Passing unfilteredChunkIndex seems arbitrary here, and we could instead pass -1 as a quick fix for the sample:

Tree.GetEntriesInRangeWithHeap(-1, transforms[i].Position, float.MaxValue, ref Scratch.Neighbours);
If the intention is to include all entities in range and if you need the seeker entities' query index within IJobChunk, it would be more appropriate to first create an index mapping to the job using kdQuery.CalculateBaseEntityIndexArrayAsync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants