Shoot projectile cylinder from one moving sphere to another moving sphere?

Then have the cylinder projectile stick inside of the receiving sphere like an arrow. The cylinder projectile would never miss, that means using a navmeshagent component I think, yes?

What tutorials would go over this concept?

Anything like http://unity3d.com/learn/tutorials/topics/projectiles ???

I found one tutorial already, but it seems like a lot of work. Is there a way to minimize the code?

[https://vilbeyli.github.io/Simple-Trajectory-Motion-Example-Unity3D/

](https://vilbeyli.github.io/Simple-Trajectory-Motion-Example-Unity3D/)

That tutorial on trajectory motion is very good. And no, it’s not a lot of code for what it does — calculating how to aim to hit a target ballistically takes a bit of math (and he spends more space explaining it than the code itself requires).

But your case sounds different. How exactly are these spheres moving? And how do you expect your cylinder to behave, such that it never misses a moving target? Is this a heat-seeking missile, or is the motion of the second sphere somehow predictable such that you can aim right where it’s going to be when you get there?

The spheres are enemy AI that move via NavMeshAgent towards a static target.

Think of it like throwing a spear towards an enemy, but never missing.

NavMeshAgent did not work as expected as a projectile.

There’s got to be an easy built in way in unity to handle projectiles that fires from a source towards a target (never misses), hit the target then stay stuck in it.

Man this is killing me lol. Aren’t there projectile solutions for unity? How do you just get a spear to get thrown at a moving object and always hit it?

Spears don’t make course corrections. So I can’t imagine that, no matter how hard I try.

What exactly is this spear supposed to do? Does it look into the future, predicting all the zigs and zags of the target, and go in a straight line for where the target will be when it gets there? (And if so, how do we avoid the paradox of the target changing its behavior after the spear is launched?) Or does it follow the target, even looping around it if necessary, all while avoiding other obstacles, like a very smart guided missile?

I don’t see why there’s got to be that. It strikes me as a rather hard problem — but begin by defining exactly what behavior you want, and then we’ll talk about how to achieve it.

Thx for your response. I’m making a tower defense game. There is an NPC that throws spears. The spears will always hit their target.

I’m currently using this code which works:

Script_NPC

SpearProjectile = Instantiate(Projectile, shotPos.position, shotPos.rotation) as Rigidbody;

Script_SpearProjectile

void Update()
  {
  transform.Translate(Vector3.forward * Time.deltaTime * 55f);
  transform.LookAt(myTarget);
  }

This works, but the spear projectile shoots in a straight line, it’s not natural looking. I was hoping to capture the natural arc of a thrown spear.