# How to make a homing projectile make a more objective path to the target?

I'm having trouble trying to get a projectile thrown by a tower to hit the player quickly.

See the image below:

The projectile hits the ground very close to where the player was.

If the player did not move so much, the projectile would certainly hit him, but even by slowing the player down and increasing the speed of the shot, the projectile often does not hit the player.

What happens almost always is the projectile orbiting the player.

If the player stands still when the tower starts firing, the projectile hits him, the problem happens when the player moves, the projectile does not follow the player correctly.

Expected result:

I have already tried to modify the speed of the player and the projectile, but I have not obtained efficient improvements in the result. I tried to modify the gravity (of the projectile and its mesh), friction. All to no avail.

Projectile BP:

EDIT 1

With this code I was able to stop the projectile from crossing the floor:

But the projectile still orbits the player:

If the player does not stop moving, the projectile orbits it indefinitely.

Below is how the components went after I turned off the physics at all.

Sphere Collision:

Static Mesh:

ProjectileMovement:

• You can check the “IsHommingPeojectile” checkbox in the ProjectileMovementComponent. – ColdSteel Sep 29 '19 at 1:18
• Dont forget to disable all the physics in projectile and its components. – ColdSteel Sep 29 '19 at 1:18
• Should I disable? Apply Impulse on Damage and Replicate Physics to Autonomus Proxy. – Boneco Sinforoso Sep 29 '19 at 17:20
• Thats your game decisions. It is important to uncheck simulates physics on every component that are in the projectile actor, otherwise bad things will happen. – ColdSteel Sep 30 '19 at 12:30
• Try to set homing acceleration magnitude to a gigantic number. – ColdSteel Oct 1 '19 at 11:56

### Intercept the target

I'm not too familiar with UE, but the behaviour you describe is consistent with the projectile "naively" accelerating towards the target's current position (from your blueprint, it looks like a constant acceleration is indeed being applied).

To actually hit a moving target, you should predict its location at the time the projectile actually reaches it, and move towards that point*.

If the projectile is significantly faster than the target, an easy approximation for that point would be:

travel time = distance to target / projectile speed
point to move towards = target position + (target velocity * travel time)


(* Recalculate periodically, e.g. once per physics tick)

• The OP wants a homing projectile - means if the target changed its direction/location/speed/acceleration it should still hit it. – ColdSteel Oct 1 '19 at 11:40
• @ColdSteel And why do you think it wouldn't do that? – Ruther Rendommeleigh Oct 1 '19 at 11:43
• Which would be just as easy as: ProjectileLocation = Normalize( targetLocation - ProjectileLocation) * speed * DeltaTime – ColdSteel Oct 1 '19 at 11:44
• @ColdSteel Yes, I think that would work as well. It would take a slightly longer path and set object positions directly, which might have frame rate implications. – Ruther Rendommeleigh Oct 1 '19 at 11:49
• @ColdSteel True. As I wrote, it's an approximation I'd recommend for a relatively fast projectile / slow target. – Ruther Rendommeleigh Oct 1 '19 at 11:57

This is probably what you need. It's for unity in C# but the maths all there.

http://wiki.unity3d.com/index.php/Trajectory_Simulation

I use this all the time and it is VERY accurate even at high speeds. It can't predict changes in direction like weaving but it will hit where the target is going to be on the dot every single time. If you want it to predict direction changes you need homing code added but you don't sound like you want homing missiles. You want projectiles.

Hope this helps.

• Very good, but too complex for me yet. – Boneco Sinforoso Oct 9 '19 at 0:30
• Ahhh, I'm telling you this is the magic. Study the crap out of it. I believe in you. This isn't very hard to implement. The hard part is understanding what to assign to what. You have all the pieces, you just need to point them all to the right place... I know how it is though. I wish I could have helped you more. – Daniel Awesome Oct 13 '19 at 4:43