i making small/mid rts game, have following need:
i want enemy players attack allies , vice versa when in each attack range.
my question is: better approach finding if enemy units in attack range of allied or vice versa of course ?
what have tried:
for tried add sknodes
skphysicsbodies
each unit node.
i can see fps going down when contact happens... guess wasn't best way know detect whether enemies in range.
i guess alternative run nested loop within update method , check if there enemy units within radius. not sure if best approach, approach may play parameters , maybe optimize routine own needs.
i know if there better alternatives.
look gameplaykit,
it may have things want.
otherwise use euclidiean distance formula https://math.stackexchange.com/questions/139600/euclidean-manhattan-distance without square root, , use value based on squads, not individual troops. (so if group of 4 soldiers attacking enemy of 5 soldiers, 1 distance check done).
the reason why not square root, because should know squared allowable distance. if enemy 10 pixels away attracts soldiers, use 100.
the best way treat soldiers squads, add them sknode (sub class add better functionality), need compare squad sknodes
if want reduce number of checks make, consider turning play area grid (like chess board). since know size of tiles, check see if units close enough warrant distance check. e.g. have unit @ a1, , enemy @ i9, know tile distance units far apart attack each other
Comments
Post a Comment