- Home /
How to get a smooth curved line between two points like those present between the nodes of bolt visual scripting.
I want to make a smooth line from point A to point B similar to what present between the nodes of bolt graph..... I want to use line renderer but the main problem is how to get some points which will make that kind of line possible.....
Answer by BastianUrbach · May 10, 2021 at 02:08 PM
One simple way is to use 4-point Bezier curves. They are pretty easy to calculate:
Vector2 Bezier(Vector2 a, Vector2 b, float t) {
return Vector2.Lerp(a, b, t);
}
Vector2 Bezier(Vector2 a, Vector2 b, Vector2 c, float t) {
return Vector2.Lerp(Bezier(a, b, t), Bezier(b, c, t), t);
}
Vector2 Bezier(Vector2 a, Vector2 b, Vector2 c, Vector2 d, float t) {
return Vector2.Lerp(Bezier(a, b, c, t), Bezier(b, c, d, t), t);
}
These functions define curves using a number of control points (a, b, c and d). You feed them an interpolation parameter t, which starts at 0 and ends at 1. The one with four control points starts at a and ends at d. The two other points (b and c) control the direction in which the curve leaves a and enters d. It's a bit difficult to explain but try around a bit with some random points and you'll quickly understand how it works.
To use these with a line renderer, generate a number of points, let's say 20, by first evaluating the function at t=0/19 then t=1/19, then t=2/19 and so on up to t=19/19. Set these points as the control points of the line renderer and you should get a nice, smooth curve.
Your answer
Follow this Question
Related Questions
Smooth Camera transition (linear interpolation) Error 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Linear interpolation crash 0 Answers
How to make a Line Renderer follow the target without delay ? 3 Answers