Hi all,
Currently working on a grid based project which requires the player to destroy ‘bad’ tiles, I’m having trouble figuring out how to handle the targeting system as it needs to update as the player(yellow and blue orb) moves with respect to its rotation. I made an attempt as you can see by the yellow outlined tiles. It is however very crude as I’m accessing a static list held by a manager object from the player script and then running a for loop to check the list against the player position(this is all being called through update, I know this is bad but I couldn’t think of an alternative).
If anyone could offer any sort of advice in terms of the approach I should take to this problem I would be extremely appreciative.
Thanks,
Renoclaf
Sounds fine to me. Since it’s based on position and rotation, then every frame all 49(7x7 area?) nearby objects could possibly change. That means you absolutely have to touch each object each frame. 49 isn’t that big a number (not like 100 units are all doing that.)
If the rotation is in set steps, you could do the math only when you change tiles or spin, but that would give tiny lag spikes. Running every frame would smooth it out.
For the “I’m too far away, uncolor me” objects, maybe call a slow coroutine when you first color something, which checks for “too far away.” Check more frequently as distance from player increases? Have a flag “I’m running my too far away checker,” to avoid double-calling. That would give a pretty, staggered winking-out effect. Alternative is to add colored items to your own watch list, but, really, the coroutine does the same thing.