Hi, i know that there's a couple of threads around with the same issue .... but none of them reached the "best practice with full performance" ....
I already profilled It and checked many melee systems around Asset store looking for the mostly "right solution"... and i couldn't reach the "pro way" ...
**WHAT I'VE ALREADY DONE TO OPTIMIZE:**
1. Created the Layer *HealthSystem* (that collides JUST with the *Weapons* Layer);
2. Created the Layer *Weapons* (that collides JUST with the *HealthSystems* Layer);
3. Created the *static Dictionary < Collider, HealthSystem > healthSystemsColliders*;
4. Created the *static Dictionary < Transform, HealthSystem > healthSystemsTransforms*;
5. Created the *static Vector3 protagonistPosition* cached once every LateUpdate and shared with all AIScripts;
6. Created the *public static event OnAttackDelegate OnProtagonistAttack* that every AI assings to that, its own *CheckForCollision(Vector3 _Blade, float _damage)* method;
7. Created the *public static Dictionary < Vector3, HealthSystem[] > battleMatrix* that stores every HealthSystem position rounded to Int, then, updated within the dictionary constantly every *LateUpdate()*;
**APPROACHS PROFILED:**
8. Sphere collider within "Protagonist" root transform on *WeaponLayer*, then a script with *OnTriggerEnter()* and *OnTriggerExit()* that manages the *private "HealthSystems[] closestTargets* and just upon *Input.GetAxis("Attack")* executes *healthSystemsColliders[collider].UpdateHealth(damage)*;
> [Average Precision and Worst Speed]
9. *Physics.OverlapSphere()* JUST upon *Input.GetAxis("Attack")*, JUST on *HealthSystemLayer* to load *private HealthSystems[] closestTargets* and then execute *"healthSystemsColliders[collider].UpdateHealth(damage)"*;
> [Average Precision and Speed]
10. Upon *Input.GetAxis("Attack")* the event *OnProtagonistAttack(BladeTransform.Position, Damage)* fires all assigned *"CheckForCollision()" * of every Active AI accross the Map checking *if ((_blade - itsPosition).sqrMagnitude < 3f)* then call *"itsHealthSystem.UpdateHealth(damage)"*;> [**Worst precision** but just Fast **(zero physics)**]
11. Upon *Input.GetAxis("Attack")* get a vector3 that corresponds to a point 1 meter towards the protagonist's facing angle, round to int the X and Z values, then call : *battleMatrix[itsPosition2D].updateHealth(Damage)*;
> [**Worst Precision** but The Fastest **(zero physics)**]
Those tests where 30 AIs against the Protagonist and i don't know if there's something faster that i didn't try yet or something that i could do to improve/balance between "performance and precision"...
↧