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.
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!
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!
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.
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!
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!
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.