Firing an arrow to predefined location

Hi all,

I am trying to instantiate and arrow from a soldier and having it hit and enemy at a predefined location. The arrow should follow a curve. However, I not sure how to tackle this. I thought Slerp was used for this, but I can’t get it to work correctly. Is there a standard function for curved trajectories in unity, or should I make my own?

var arrow = Instantiate(arrowPrefab, transform.position, Quaternion.identity);
arrow.transform.position = Vector3.Slerp(transform.position, currentTarget.position, 1.0f);

You need to call Slerp repeatedly over time; it’s not a function that you can only call once if you want to use it in an animation. The third parameter is a float which you should increase gradually from 0.0 to 1.0.

–Eric

Thanks, I missed that. So it needs to go in update? Is there any way to alter the curve or does it always follow the same one?

It would probably be better in a coroutine, depending on what you’re doing. It spherically interpolates so it would always be the same curve.

–Eric