- A* version: 5.4.4
- Unity version: 6.0.38f1
When spawning a character, I want to spawn it in a location that doesn’t overlap with the radius of another character’s followerEntity.
Since the character doesn’t have a collider, I can’t use Physics2D.OverlapCircle.
Is there a way to check if a followerEntity exists within a certain radius of a specific location, similar to Physics2D.OverlapCircle?
I think you just want
// 'follower' being the Follower that already exists
float distance = Vector3.Distance(myDesiredPosition, follower.position);
if (distance > follower.radius){
// Success!!
}
If you want to check for a direct overlap. You can also add spacing this way.
Is there any way to check without access to the objects of the spawned characters?
Hi
If you use local avoidance, you could likely use:
var simulator = RVOSimulator.active.GetSimulator();
var rwlock = simulator.LockSimulationDataReadOnly();
rwlock.dependency.Complete();
if (simulator.quadtree.QueryArea(somePosition, someRadius) == 0) {
// Empty
}
rwlock.UnlockAfter(default);
(I haven’t tested the code above, but I think it should work)
I tried it but sadly it doesn’t work
Which suggestion are you referring to- mine, Aron’s, or both? And what results are you seeing with these solutions?
Feel free to elaborate more on this if you need- not sure which character is the “spawned” one in this context. From the onset though I’d say this may be more of a personal design decision to be able to find a way to access the units if you don’t have a reference to them. Caching them on spawn, accessing them through an interface, etc. If none of that sounds plausible let me know what you’re trying to do and I’ll see what I can help with.
As you mentioned, I can find the spawn position by caching and accessing the spawned characters’ objects to check the distance between them.
I believe this won’t be an issue at all when the number of spawned characters is small.
However, if the number of spawned characters is 5,000 and I need to find spawn positions for an additional 500 characters without overlap,
it would require 5000 * N * 500 distance calculations (N is the number of attempts to find a non-overlapping position per new character).
To avoid potential performance issues, I wanted to know if there is a method similar to Physics2D.OverlapCircle that allows checking the area regardless of the number of already spawned characters.
I see. I dug around and I couldn’t find anything in the codebase that may accomplish this- no “AgentOverlap” method or similar that I can find. Aron may know of one that I’m just unaware of.
I think your best bet here may be some type of location manager for your agents. If there are 5000 thousand agents on the map, we only need to scan the ones nearby at least a suitable location. Agents can hold a reference to what “section” of the map they’re at and maybe attach a self-reported reference to themselves to the section their in. Then you just iterate through that, which may be closer to 1000 or 500 or even 100 depending on how tightly you define your sections– that takes it from 5000 x N x 500 to 1000 x N x 500. That’s just off the top my head- I think there’s probably smarter/more things you can do to bring these numbers down more.
Sadly though, I’m not aware of any “check nearby/overlapping agents” method. (EDIT: as far as anything not provided already by Aron***)
Well, the built-in way to do this is what I wrote as a code sample above. There’s no other built-in way.