I am using a parabola curve to launch my arrows:
public static Vector3 Parabola(Vector3 start, Vector3 end, float height, float t)
{
Func<float, float> f = x => -4 * height * x * x + 4 * height * x;
var mid = Vector3.Lerp(start, end, t);
return new Vector3(mid.x, f(t) + Mathf.Lerp(start.y, end.y, t), mid.z);
}
I have a projectile that is a simple capsule scaled down to be long and thin like an arrow. I've tried every way to rotate it I could find online, but there is always something off. In order to follow the curve I need the direction between the last position and the new position, so I have been trying things like:
void ParabolaMovement() //Called in Update()
{
parabolaAnim += Time.deltaTime;
parabolaAnim = parabolaAnim % 5;
Vector3 newPos = MathParabola.Parabola(start, target, 5f, parabolaAnim / 5);
Vector3 dir = newPos - transform.position;
transform.LookAt(dir);
transform.position = newPos;
}
As for what is going wrong, it does not point AT the target, which I udnerstand it can't because nowhere do I specify target pos, which I should, but don't know where. I cannot simply tell it to lookat target, since I want it to lookat the direction it is currently going in the curve, but it also needs to face the target.