How can i set the projectile to go on the hit result of the SphereTraceObject?(self-guided projectile)

Hi, I’m new on ue4 hand i have this issue…
i want to build a self-guided projectile that goes on the first enemy near to it

when i use the TELEPORT node all is work fine but i can’t see the projectile path,
instead if i try the MoveComponentTo i can’t even connect the return value of the SpawnActor.
what should i do?

im assuming here that your aim is to fire a projectile that you can see in game and have it chase a player. if thats the case then i believe you are over complicating things a bit and theres a few easy options to get things working. in both cases we will make use of the projectile movement component and its homing abilities.

for the first option you could create your projectile actor add in the projectile movement component and with the movement component selected go to the details panel and check the box for homing and set homing acceleration in the homing section. next you could add collision component that is larger than the projectile which will serve as the radius checked for potential homing targets. from there you just need a simple script: on begin overlap, cast to target class (character, pawn, etc), and set homing target component (example below). with this you may need to make a check so the projectile doesnt chase the one that shot it though.

the second option works more like what you currently have. first you setup the movement component as above (first sentence of last paragraph). then you do the targeting work in your character by running a trace and using the hit actor in the trace as the target. i added a example of the script needed below though it would be placed in the character and not in the projectile as shown ( i was to lazy to add 2 pictures). again in this case i would add in a cast to ensure that your hit object was of the type you want to target before setting the homing target.

I know it’s more than a few years old, but I’d love to get my answer.
Currently, I’m making a Tower Defense game and I want the projectiles coming out of tower to hit a single target (actor), which is moving along a Spline.
I’m using the Homing feature and it works perfectly, as long as my target is stationary. However, once my target starts to move (either using Spline or a simple Projectile Movement), my Tower projectiles cannot hit it correctly. They miss their target, rotate around it, miss it again, rotate around it again, and finally they can hit it. What can I do to fix this?

Do you want to them to always hit? If so, the PMC’s Homing Target is probably not the best choice since it’s in its inherent nature to provide a chance to be dodged. If you wanted extra accuracy, we’d need to factor target’s velocity, calculate lead and home in on that instead. But even if you did that, a rapid change of direction (90° turns are common in Tower Defence, right?) would still prove problematic.


Perhaps you need another, less realistic method. Physically Accurate Projectile Simulations may not mesh well with a TD game - do tell if that is actually required. Or do we simply need to hit…

Hitting the target is required.
I tried manipulating the velocity vector of ProjectileMovement, instead of having Homing activated, but that seems not possible as I can’t feed the FindLookAtRotation to it.
Then I tried adding a RotatingMovement component, but that didn’t work either as Projectile Movement dictates its own rotation over the RotatingMovement.
At this point I think I should probably use a game controller and make my projectiles AI, but I doubt if that is a wise decision to have so many projectiles in the scene and all being AI.

It seems like I finally made it happen!
Instead of using the Homing feature, I simply created the ProjectileMovement vector myself.
I used the initial location of my projectile and my target in the FindLookAtRotation. Then I extracted a VectorForward from its result, and multiplied Vector by a float to set the speed.
Then, I set the resulting vector to SetVelocity, extracted from my ProjectileMovement component.
The only thing is I did this in Tick, and I’m not sure if it’s optimized for all projectiles in the scene with different speeds.

Consider:

  • skipping the PMC and vInterpTo to target (or the constant variant)
  • skipping the PMC and Timeline Lerp to target (you could even dynamically spawn a spline and drive projectiles along an elaborate path)
  • using the PMC Homing Target while also nudging it with physical forces (may not always hit, though)

Rotation can be obtained in many ways. For example: Find Look at Rotation using the projectile’s location from previous frame and the projectile’s current location.


If you want something truly performant, since we may be talking about 100s of projectiles* (right?), look into Niagara.

1 Like