My game uses a targeting system where the player can mark multiple enemies and then with the click of a button fire a homing projectile at every marked enemy. And the projectile should be guaranteed to hit. My problem is that if a different enemy (that is not the target of the given projectile) gets in the way of the homing projectile that is locked onto a different enemy it generates the hit overlap and everything goes to shit. My question is if anybody has an idea as to how to go about giving each fired projectile a designated enemy that is the only enemy it can overlap with. Sorry if I failed to explain this problem well but any help would be appreciated. Thank you.
You give the projectile movement component a target at some point so it can home onto something (bottom - you probably do it elsewhere, here only to visualise). Rather than overriding Actor Overlap, use the mesh of the projectile (or a sphere collision) to check what the *other *hit component is. This way you get to control what happens when the entities start to overlap. Here, we check whether the projectile mesh overlaps with the intended (Scene Component) target; you can ignore conditional False results and only execute relevant code if True.
Alternatively, if you’re dealing with just a handful of homing targets at a time, you could set up collision channels. Each target / projectile gets a unique one and will not interact with anything else in the world. You can only have handful of those, though:
Here’s a short piece on collision filtering:
Yet another way is to set up a basic ID system. Each target / projectile is assigned an int and a conditional check compares the IDs when overlap triggers. You’ll then know whether you’ve hit the intended target with the correct ID, and either execute the rest of the script or not.
Thank you! That gave me the idea to fix it! Basically just as you do in the top picture but I’m now setting a public variable in my projectile called intendedTarget which is of type Enemy and then in my overlap hit event on the projectile I do basically the same branch just with other actor checking that the enemy I’m overlapping is the same as the intendedTarget. Thanks again!