- Home /
Interpolating along an arc.
I am trying to move an object between two points along an arc with respect to another point. I have a starting point A, an end point B and third point C. I want to make my object move from A to B along an curved path where the convex side of the path is facing away from point C.
I tried using Vector3.Slerp as shown in the documentation and I can get the curved path, but sometimes the path is flipped and the object goes through C.
My code is very similar to this example. How can I get the path to always be go away from C?
Is this 2D or 3D. Are points A and B equal distant from point C? An example that fails might help get an answer.
They are 3d points. I would have to test it out some more to come up with points that caused it.
Answer by darthtelle · Mar 26, 2014 at 11:57 AM
You should use a Bezier curve if you have a third influential point. It includes a curve script which plots the points of the curve, however with a bit of alteration it can be used similar to lerping (without using the Vector3.Lerp function). Just substitue 't' for your timer.
Vector3 bezierPosition = (((1 - timer) * (1 - timer)) * m_StartPosition) + (((1 - timer) * 2.0f) * timer * m_CurvePosition) + ((timer * timer) * m_TargetPosition);
I took a look at this and in the examples given the third influential point is on the wrong side of the curve. Also, I got strange results when testing the formula you suggested. It does curve between the two points, but it doesn't always curve away from the influential point and sometimes create very large curves between points close together.
Ah, with bezier curves they curve towards the influential point. Perhaps if you find a similar point on the side you wish to curve towards it'll fit more to what you're looking for. Alternatively, you could use a sin or cos wave to create a path. Use a sin/cos similar to lerping but only affecting the x and z positions (or whichever axis the path moves along).