|Topic was automatically imported from the old Question2Answer platform.
I have a tank project going and have come across a problem with area collision for my turret aiming. what will happen is the turret aims at targets as they enter the area, if I drive two tanks into the area , then drive one tank out the enemy tank will lose the remaining tank even if it was the tank it was targeting. I have on body exited set to change target to null , but even if I change that to just pass the tanks just keep target lock after they exit the area leaving the enemy or player tank targeting an exited body while other bodies are still in the area.
can I check the area for remaining tanks? or maybe store targets as they enter the area would work?
This is a very confusing explanation. It is much better and much simpler to just share your code. Please share your tank controller script as well as a screenshot of your scene tree.
Bernard Cloutier | 2020-09-29 15:59
Thank you Bernard Cloutier for the reply , sorry my question is confusing , the turret has an area 2d with a collision shape to detect a tank in range and target the intruding body , it was adapted from KidsCanCode tank tutorial. I just needed to expand on the idea so I added an array to store the intruding bodies and then remove them in the on body exited function and targeting is not set to null until the array is empty, it seems to work good , I used “array.pushback(body)” so the turret doesn’t re-target for each unit that enters its field.
ArthurER | 2020-09-29 16:50
Please copy and paste your code and add screenshots of your project’s scene tree. It is very hard to diagnose the source of the problem without them.
Bernard Cloutier | 2020-09-29 19:58