What is more efficient

Question about efficiency:

Scenario there are three buildings we will call ‘Targets’ being attacked by 100 rigs we will call ‘Attackers’ which are all in the same folder. The targets need to detect what the closest rig to them is.

Do I:

A) Go through the folder of attackers doing a standard magnitude checking function to find which is closest by magnitude.

B) Have a cylinder centred on the ‘Target’ which I call GetTouchingParts() on then work out which are rigs and perform magnitude calculations of that.

C) your suggestions.

1 Like

A. Is probably the inevitable method unless you have some other extended factors such as regions which might allow you to cut calculations. You sort of have to cycle through the list constantly to check if they are in range or not anyway, so you may as well continue with this and store it.

B. Would produce other errors such as hitboxes and collisions down the line so please avoid using a massive hitbox. It would also not work 100% of the time as you haven’t considered if your target is on a different level (as it would have to be a sphere with radius x). B is also basically just A but you’ve attached a huge box to you (imagine every possible valid co-ordinate being represented in A, it would form a giant sphere).

You also have to remember this is a computer doing this, 100 calculations is nothing especially when its something like magnitude.


Kk, gonna clear up some things since I feel I was a bit unclear in some respects and im interested if your answer is consistent.

I don’t mind the detection not being perfect, its in no way critical to the method being successful.

Everything is on a flat arena

My logic behind it was if only a third of enemies are within the box it may be more efficient.

Well, thats the beauty of programming. You can do whatever method you choose providing at the end of the day your happy with it. :smile:

Method A is more robust and has better applications, whilst also reducing load on the physics engine (as it doesn’t have to handle the physics of the giant cylinder). If you don’t want it to be perfect then ok I respect that, but then it begs the question of why would you go to more effort then actually needed - especially as calculating magnitude can be done on mass by a single script with the likeliness of their being some unknown error being basically 0.

1 Like

Ok given you feel it may have physics implications and the fact a third of the micro profiler is currently physics ill probs stick with option A then, Cheers for your help!