[SOLVED] DOTS How to get closest entity position with Overlap sphere

Hello, we are developing a game with dots. I want to take the position of closest enemy entity around my character with using overlap sphere, in dots physics Can somebody help?

8578492--1149067--Screenshot 2022-11-11 at 11.45.25.jpg

Yup, you can do sphere overlaps using the physics package:

float3 position;
float radius;
var hits = new NativeList<DistanceHit>(100, Allocator.Temp);
CollisionFilter filter;
GetSingleton<PhysicsWorldSingleton>().OverlapSphere(position, radius, ref hits, filter);
1 Like

And if you only want the closest, you can call OverlapSphereCustom instead and pass it a ClosestHitCollector.

Much thanks for your reply @scottjdaley .
Btw, i'v solved this problem using CalculateDistance collision query defined in PhysicsWorld.cs.

further read for those dealing with this kind of work : Spatial Queries And Distance

1 Like