So I was just playtesting a GUI-based tower defense game I’ve been working on. Script activity was at over 60% when 40ish enemies spawned…
Every frame, I update each enemy and use magnitude to determine how close they are to their target node. (for their path movement, to know when to change their direction.)
Apparently, that’s very expensive. I can’t really do anything else though, because for projectiles I’m going to be using similar collision code to determine if it hits an enemy, I’d have to iterate over all the enemies for each projectile to see if it’s touching any of them.
Magnitude doesn’t even seem to be the culprit, it appears any arithmetic operation on the Absolute properties seems to make that activity rating spike.
Any tips for optimizing this? I didn’t experience any FPS drops, but 60% activity is something else…