- Home /
Full Performance On Melee Combat
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:
Created the Layer HealthSystem (that collides JUST with the Weapons Layer);
Created the Layer Weapons (that collides JUST with the HealthSystems Layer);
Created the static Dictionary < Collider, HealthSystem > healthSystemsColliders;
Created the static Dictionary < Transform, HealthSystem > healthSystemsTransforms;
Created the static Vector3 protagonistPosition cached once every LateUpdate and shared with all AIScripts;
Created the public static event OnAttackDelegate OnProtagonistAttack that every AI assings to that, its own CheckForCollision(Vector3 _Blade, float _damage) method;
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:
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]
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]
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)]
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"...
Your answer
Follow this Question
Related Questions
OnTriggerEnter2D not Working 0 Answers
collider doesnt work the 2nd time 1 Answer
overlapsphere to destroy NPCs on exit 1 Answer