How do I draw a Bézier curve to have 90 degree angles ?
Hi guys , I am trying yo understand how to draw bezier curves that have 90 degree angles like this
Here is a method i use to draw a curve between two points. The typical script you usually see for drawing bezier curves in unity.
However this give me a very curvy bezier , I am trying to get the bezier to have 90* angles where they would usually curve
public static void DrawConnector(Vector2 statPoint, Vector2 endPoint)
{
Event e = new Event();
Vector3 startPos = new Vector3(statPoint.x, statPoint.y);
Vector3 endPos = new Vector3(endPoint.x, endPoint.y);
Vector3 startTan = startPos + Vector3.right * 50;
Vector3 endTan = endPos + Vector3.left * 50;
Color bizcol = (endPoint != e.mousePosition) ? Color.red: Color.blue);
for (int i = 0; i < 1; i++)
Handles.DrawBezier(startPos, endPos, startTan, endTan, bizcol, null, 2);
}
No, see my answer below. 0 tangents would give you something like this: http://cubic-bezier.com/#0,0,1,1 (i.e. a straight line)
Answer by phil_me_up · Feb 25, 2016 at 10:03 PM
A tool like this will help visualise what you're doing: http://cubic-bezier.com/#.55,0,.44,.99
What you probably want is something more like this: http://cubic-bezier.com/#.55,0,1,.4
Note that in your code your first tangent is Vector3.right, and the second is Vector3.left (illustrated in the first link), where as you'll probably want one tangent as Vector3.right, and the other as Vector3.down (or Vector3.up * -1 as I'd write it)
Why? Well consider what a tangent is. At your control points (the start and end positions), in natural language a tangent is a line which will just touch the control point and be completely parallel to the curve at that point.
For what I'm seeing here , I would really need to piece together multiple bezier curves to get this effect then ? This is what i am ai$$anonymous$$g for
Also, that link is great !! thanks for that.
Your answer
Follow this Question
Related Questions
Moving an array of Vector3 with the GameObject (Path-System) 0 Answers
Set new default position each time? 1 Answer
Why are my Vector3s returning inaccurate floats? I don't think it's the debug .ToString() issue. 2 Answers
Drawing to an editable spline in game view 1 Answer
Access an Array of class inside another Array of class? (EditorGUILayout) 1 Answer