Trying to mark closest enemy with a blueprint so player projectiles will home-in to enemy

Hello! I am trying to make a blueprint on my player character.
I have a base parent for enemies, and player. I did put an invisibile mark on Parent Enemy Blueprint.

What I am trying to achieve:
-When player presses “I”, the player detects enemies in a certain radius
-A mark appears on enemy, which then the projectiles will home in
-If the player presses it again, the mark becomes invisible on that enemy, and appears for new closest enemy.

I was able to make the mark visible for closest enemy. Though the things I could not figure are:
-It does not go invisible if the mark is visible. So multiple enemies get marked after multiple scans.
-How to make projectiles home in to THAT specific enemy.

Hey @Riso222! Welcome to the forums!

So there’s a few things here you need to do:
When you use “Cast To BP_Enemy_Base”, rightclick that pin and promote that to a variable. Then you’ll take that variable and after your ScanClosest event but before the cast, GET that variable and Target->Crosshair Mark->Set Visibility False.

What that should do is take the old enemy you had selected (that’s the variable) and set the crosshair mark to not visible BEFORE looking for a new actor. This all happens so fast that if it’s the same actor, chances are you won’t even see it change.

One problem at a time, let’s sort this out before the bullet homing! :slight_smile:

Thanks for the help so far! I hope I am doing it right here?
(Sorry for any inconvenience I am pretty new so…)
(edited the image-)

What that should do is take the old enemy you had selected (that’s the variable) and set the crosshair mark to not visible BEFORE looking for a new actor. This all happens so fast that if it’s the same actor, chances are you won’t even see it change.

One problem at a time, let’s sort this out before the bullet homing! :slight_smile:

I think this looks great! You may want to rename that “As BP…” variable for less confusion but otherwise looks good!

Did you test it yet? What were the results?

Let us know!

I did some testing!

Had to do this small changes and then it worked flawlessly!

(Mark Visible is on Enemy Blueprint parent. so I can detect which enemy is marked etc. as well!)

Then added this small bit to my player projectile base, along with a sphere collision so if marked enemy is overlapped, the projectile homes to them.

Though I feel like it can be cleaner. Because:
-It seems that the “homing in” actually triggers once, due to how “Begin Overlap” works and projectile sometimes goes on with its original traction. Which is just going forward.

Though at least it fundementally works!

Okay, so regarding the projectile-

If you haven’t, you will likely want to make a projectile actor instead of it being a component of your character.

It can be a simple actor, with projectile movement component. This will not only make it easier to have different types of attacks, but also the movement can be handled independently and keep from bogging down your player character’s code too much.

I made a quick mock-up you can use for that- the first picture is code on the projectile (I didn’t add collision code, you can do that yourself just fine).

The second pic is how I’m spawning it. As long as your targeting code works- and it does- this would work nicely for you!

Let me know if you have any questions!

Ah wait its my bad-
Projectile IS an actor! sorry for not sharing before!

I did follow a few lessons I found to use as base and modify the things and add on top of it for practice- And there was a projectile system luckily!

Okay then! It’s really blurry but I think this looks good- just look at the tick part I posted.
What that does is make the target look from it’s current location towards the target. The ProjectileMovement Component will continue its movement, the tick function is specifically to make it rotate its forward direction towards the target, giving it a homing effect!

I was also doing some side research and learned
image
This does exist

Can I use it in this situation here? At least it looks like I could help a lot unless its buggy or broken-

So it’s kind of a YMMV situation, it depends on what kind of projectile you’re working with.

I modified that mockup to use this, if you want to go this direction. It’s functionally the same, but you can allow things to miss if the target moves quickly because the acceleration is basically the “Turning” on it. Higher value means faster turning.

Red is the projectile’s face turning towards target, yellow is speeds, play around with the movement before adjusting the homing acceleration.

OH THIS WORKED QUITE WELL. THANKS A LOT! I just had to add a small thing or two but this worked perfectly!

1 Like