- Home /
Move Vectors as curve towards Target
So, I am struggling with this for a couple hours now. I have several points that should move to a target with a curve, depending on their position.
An example can be seen in the picture below.
I already tried using the distance the points traveled and adjusting the angle of the vector, but it doesn't quite work.
Has anyone an idea what the best way is to implement it?
Answer by Summit_Peak · Mar 13, 2018 at 12:51 AM
Try:
Vector3 t = (normalize(target.position - point.position) + normalize(point.velocity)) / 2;
point.position += point.velocity.magnitude * t * Time.deltaTime;
Thank you for your reply. But I think your code could only work, if the point already has a velocity, which points to the side. If they are standing stil, they will just go straight to the target. Or am I missing something?
You can give them an initial velocity:
struct Point { public Vector3 position; public Vector3 velocity; }
Vector3 InitialVelocity(Point[] points)
{
Vector3 v = Vector3.zero;
for (int i = 0; i < points.Length; i++)
v += (points[i].position - target.position).normalized;
v /= points.Length;
for (int i = 0; i < points.Length; i++)
points[i].velocity = v;
return v;
}
Your answer
Follow this Question
Related Questions
Change direction of vector based on which way player is facing 1 Answer
More simple vector math... 2 Answers
Math Optimization: Normalize 2 Answers
Converting an Azimuthal Coordinate to Vector3D? 1 Answer
Get field between x points 0 Answers