Questions in topic: "bezier"
http://answers.unity.com/questions/topics/single/624.html
The latest questions for the topic "bezier"Combining bezier curves
http://answers.unity.com/questions/1661985/combining-bezier-curves.html
I'm trying to create endless road racing game. In order to generate the road, I'm planning to use bezier curves and combine them to create the road. I have the code create a cubic bezier curve using 4 points but how can I join them together. This is the code I have so far:
public class Bezier : MonoBehaviour
{
public LineRenderer lineRenderer;
public Transform[] point0, point1, point2, point3;
private int numPoints = 50;
private Vector3 positions = new Vector3[50];
void Start()
{
lineRenderer.positionCount = numPoints;
DrawCubic();
}
private void DrawCubic()
{
for (int i = 1; i <= numPoints; i++)
{
float t = i / (float)numPoints;
positions[i - 1] = CalcCubic(t, point0.position, point1.position, point2.position, point3.position);
}
lineRenderer.SetPositions(positions);
}
void Update()
{
DrawCubic();
}
private Vector3 CalcCubic(float t, Vector3 p0, Vector3 p1, Vector3 p2,Vector3 p3)
{
float u = 1 - t;
float tt = t * t;
float uu = u * u;
float uuu = uu * u;
float ttt = tt * t;
Vector3 p = uuu * p0;
p += 3 * uu * t * p1;
p += 3 * u * tt * p2;
p += ttt * p3;
return p;
}bezierFri, 30 Aug 2019 17:17:34 GMTsinglearrowgamesBezier pipe in Probuilder
http://answers.unity.com/questions/1654329/bezier-pipe-in-probuilder.html
Hello, <br>
I want to make a bezier pipe using pro build, the problem is when I create one, it becomes transparent when I move through it until I flip normals, it becomes the pipe I wanted but this time the outside is not visible, it only show's what's inside...<br>
I wanna make a pipe ( like the one in pro builder ) but in bezier shape, how could I do that <br>
ThankspipelinebezierSat, 03 Aug 2019 15:21:47 GMTXsodiazHow to make game objects follow a path in order in Unity along a bezier curve
http://answers.unity.com/questions/1646941/how-to-make-game-objects-follow-a-path-in-order-in.html
I have a single Object moving along a Bezier Curve but i have multiple objects that need to follow this path in order but they all follow at the same time.The object is a snake type enemy in a space shooter game.
I have so far tried to make all objects children but in doing this they remain in a straight line to the parent when follow the Bezier Curve. I have also made all objects separate and attached the Bezier Script to these so they all follow the same route and this works but only they follow the same path at the same time.
I think what i need to do is have each object not be a child object and all have the script attached to follow the route but also have a delayed time before it follows along the path but not sure how to go about this. I was thinking this might need to be done in a separate script because in the bezier curve script it is set so the object starts again at the beginning of the route once reaches the end
public class BezierFollow : MonoBehaviour
{
[SerializeField]
private Transform[] routes;
private int routeToGo;
private float tParam;
private Vector2 enemyPosition;
[SerializeField]
public float speedModifier = 0.5f;
private bool coroutineAloud;
// Start is called before the first frame update
void Start()
{
routeToGo = 0;
tParam = 0f;
//speedModifier = 0.5f;
coroutineAloud = true;
}
// Update is called once per frame
void Update()
{
if (coroutineAloud)
{
StartCoroutine(GoByTheRouteRoutine(routeToGo));
}
}
private IEnumerator GoByTheRouteRoutine(int routeNumber)
{
coroutineAloud = false;
Vector2 p0 = routes[routeNumber].GetChild(0).position;
Vector2 p1 = routes[routeNumber].GetChild(1).position;
Vector2 p2 = routes[routeNumber].GetChild(2).position;
Vector2 p3 = routes[routeNumber].GetChild(3).position;
while (tParam < 1)
{
tParam += Time.deltaTime * speedModifier;
enemyPosition = Mathf.Pow(1 - tParam, 3) * p0 +
3 * Mathf.Pow(1 - tParam, 2) * tParam * p1 +
3 * (1 - tParam) * Mathf.Pow(tParam, 2) * p2 +
Mathf.Pow(tParam, 3) * p3;
transform.position = enemyPosition;
yield return new WaitForEndOfFrame();
}
tParam = 0f;
routeToGo += 1;
if (routeToGo > routes.Length - 1)
routeToGo = 0;
coroutineAloud = true;
}
}c#delaybezierTue, 09 Jul 2019 11:51:59 GMTjamie2dogBezier curver using LineRenderer
http://answers.unity.com/questions/1618605/bezier-curver-using-linerenderer.html
Hi!
I'm trying to make a bezier curve between two GameObjects using Unity's LineRenderer, but I'm stuck. Here is the code I'm using at the moment:
public GameObject source;
public GameObject target;
private Vector3[] lineVertexPositions;
private LineRenderer lineRenderer;
void Start()
{
lineRenderer = GetComponent<LineRenderer>();
lineRenderer.positionCount = 3;
SetVertexPositios();
for (int i = 0; i < lineRenderer.positionCount; i++)
{
lineRenderer.SetPosition(i, lineVertexPositions[i]);
}
}
void SetVertexPositios ()
{
lineVertexPositions[0] = source.transform.position;
lineVertexPositions[1] = source.transform.position - target.transform.position;
lineVertexPositions[2] = source.transform.position;
}rendererlinerendererlinecurvebezierWed, 03 Apr 2019 13:23:07 GMTratchetunityHow to dynamically set transform positions (for a Bezier curve)?
http://answers.unity.com/questions/1617377/how-to-dynamically-set-transform-positions-for-a-b.html
Hey everyone, I'm remaking a level from Mega Man 2 and I'm having trouble with this dog enemy. I have the dog which instantiates a certain number of fireballs every couple of seconds which seems to be working, but I seem to have messed up the fireball movement. The movement is supposed to be parabolic, so I tried using a three-point Bezier curve. The three points for the curve are attached to the dog (cause if I duplicate the dog I wanted the points to move with the new dog), the fireballs spawn, but I don't know how to set these point so that the fireballs can follow them. Any help is appreciated!
Fireball movement code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Fireball : MonoBehaviour {
[Header("Set in Inspector")]
public float duration = 1f; // the number of seconds for the lerp
[Header("Set Dynamically")]
public float timeStart;
public Transform p0;
public Transform p1;
public Transform p2;
private void Start()
{
timeStart = Time.time;
}
void Update ()
{
float u = (Time.time - timeStart) / duration;
u = u % 1f; // make sure u is always between 0 and 1
Vector2 p01 = (1 - u) * p0.position + u * p1.position;
Vector2 p12 = (1 - u) * p1.position + u * p2.position;
Vector2 p012 = (1 - u) * p01 + u * p12;
transform.position = p012;
}
}
Dog Controller code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DogController : MonoBehaviour {
[Header("Set in Inspector")]
public Transform fireballSpawnPoint;
public GameObject fireballPrefab;
public float timeBetweenShots = 1.5f;
private float ranVal;
void Start ()
{
Invoke("FireShoot", timeBetweenShots); // first fireball shot from the dog
}
void FireShoot()
{
ranVal = Random.value;
if (ranVal <= 0.33)
{
StartCoroutine(ShootThree());
Invoke("FireShoot", timeBetweenShots); // first fireball shot from the dog
}
else if (ranVal > 0.33 && ranVal < 0.66)
{
StartCoroutine(ShootSix());
Invoke("FireShoot", timeBetweenShots); // first fireball shot from the dog
}
else
{
StartCoroutine(ShootNine());
Invoke("FireShoot", timeBetweenShots); // first fireball shot from the dog
}
}
IEnumerator ShootThree()
{
for (int i = 0; i < 3; i++)
{
Instantiate(fireballPrefab, fireballSpawnPoint.position, Quaternion.identity);
}
yield return new WaitForSeconds(1);
}
IEnumerator ShootSix()
{
for (int i = 0; i < 6; i++)
{
Instantiate(fireballPrefab, fireballSpawnPoint.position, Quaternion.identity);
}
yield return new WaitForSeconds(1);
}
IEnumerator ShootNine()
{
for (int i = 0; i < 9; i++)
{
Instantiate(fireballPrefab, fireballSpawnPoint.position, Quaternion.identity);
}
yield return new WaitForSeconds(1);
}
}movementtransformpositiondynamicallybezierFri, 29 Mar 2019 22:37:04 GMTTysonGSpawn 1-4 players around a Bezier curve?
http://answers.unity.com/questions/1615761/spawn-1-4-players-around-a-bezier-curve.html
I need to spawn 1-4 players at points around a bezier curve surrounding a basketball net (so around a 3-point line, essentially). This will be an AR environment, so there will be no actual 3-point line in the scene - I need a way to spawn a given number of players at equal distances from each other. So if there are 2 players, they will be placed at 10 and 2 of a clock-face. 4 players will be placed at roughly 9, 11, 1, and 3 of a clock-face.
**Note:** No player can be on the top of the oval (directly facing the net), as this would be an unfair advantage.
![alt text][1]
[1]: /storage/temp/135271-image.pngmathspawningaugmented-realitybezierSun, 24 Mar 2019 23:27:20 GMTdcox45Raycast Down with Approximation Search
http://answers.unity.com/questions/1606745/raycast-down-with-approximation-search.html
I've got an approximation search and would like to ad from the BezierCurve Point the Point on the Ground. => but for correct Result the Point on the Ground must be calculated every Time on the approximation search (*due to correct distances*)
<br>
***Approximation Search Code***:
<br>
float step = 0.1f;
float t = step;
float lastT = new float();
float distance = 5;
/* Bezier.GetPoint(Vector3_A,Vector3_B,Vector3_C,Vector3_D,t) is a Vector3 Equation for a Point on the Bezier Curve */
while (t >= 0 && t <= 1f)
{
while (t < 1f && Vector3.Distance(Bezier.GetPoint(Vector3_A,Vector3_B,Vector3_C,Vector3_D,t), last_spawn) < distance){
t += step;}
step /= 100;
while (t > lastT && Vector3.Distance(Bezier.GetPoint(Vector3_A,Vector3_B,Vector3_C,Vector3_D,t), last_spawn) > distance){
t -= step;}
step /= 100;
if (t > 1f || t < lastT){
break;}
if(step < 0.000001f){
myList.Add(Bezier.GetPoint(Vector3_A,Vector3_B,Vector3_C,Vector3_D,t));
lastT = t;
step = 0.1f;
}
}
(*Pseudo Code*)
<br>
Now because the BezierLine is never really aligned with the Surface (*Terrain*) I need to get the Point on the Ground. If I now Add following `Vector3.RaycastDown_Position();` to the `Bezier.GetPoint(a,b,c,d,t);` Method => `Bezier.GetPoint(a,b,c,d,t).RaycastDown_Position();`
the Editor will freeze and get's Laggy!
<br>
***Raycast Down Code***
<br>
public static Vector3 RaycastDown_Position(this Vector3 t){
RaycastHit hit;
if(Physics.Raycast(t + (Vector3.up * 20),Vector3.down,out hit,Mathf.Infinity)){
t.y = hit.point.y;
}
return t;
}
<br>
**Question:**
What would be a better Approach to avoid Laggy Editor, or even Freezes?
<br>
if I add the RaycastDown Method after the approximation search, it'l cause inaccurate Result at the distance between the Calculated Points!
thanks @Bunny83 for any suggestion =)c#raycastvector3beziercalculationsTue, 26 Feb 2019 18:57:49 GMTdan_wipfSubdivide Bezier Curves
http://answers.unity.com/questions/1599711/subdivide-bezier-curves.html
hi, i want to achieve that I can subdivide a Bezier Curve with a given distance. Now it works if the Bezier is a straight line, but if I change a Controll-Point so the Bezier get's curved, the Distance will be off what I wanted to achieve! => see pictures at the End of Post
----------
How I get the Subdivision is:
float t = Distance between subdividedParts / bezier length;
//A,B,C,D = ControllPoints of Bezier
GetPoint(A,B,C,D,t);
//GetPoint equation:
public static Vector3 GetPoint (Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) {
t = Mathf.Clamp01(t);
float OneMinusT = 1f - t;
return
OneMinusT * OneMinusT * OneMinusT * p0 +
3f * OneMinusT * OneMinusT * t * p1 +
3f * OneMinusT * t * t * p2 +
t * t * t * p3;
}
----------
I hope enough Information is provided.
Dan
----------
![Straight][1]
----------
![Curved][2]
----------
![bezier-explenation][3]
[1]: /storage/temp/132741-bezier-straight.png
[2]: /storage/temp/132742-bezier-curved.png
[3]: https://answers.unity.com/storage/attachments/132853-bezier-explenation.jpgc#mathcurvealgorithmbezierFri, 08 Feb 2019 14:03:50 GMTdan_wipfBaked Animation VS Bezier Tween
http://answers.unity.com/questions/1585080/baked-animation-vs-tween-beziers.html
i'm slightly sure this question is not a duplicate.
is there a big **performance** different between :
----------------------------------------
1. using a character model which is animated via baking whole of the key frames and has a big size of *20 Mb* (each frame is a keyframe)
2. using another one with just fewer keyframes and use bezier tween's which causes to have a size of *3 Mb*
----------
**Aspects of comparison are**
1. RAM usage
2. Load(prepare) time
3. CPU activity for playing cycles
4. Any importent thing else
for me, reverting baked animations to tweened ones is a big cost. tnxanimationanimatorfbxbezierSun, 30 Dec 2018 16:22:44 GMTpaysabMesh generated from bezier curve loop going outside loop
http://answers.unity.com/questions/1557078/mesh-generated-from-bezier-curve-loop-going-outsid.html
Hello,
I am generating a mesh plane that conforms to a bezier curve loop.
I get evenly spaced points along along the curve, and set them as the vertices of the new mesh.
The problem comes when setting the triangles.
If a point along the bezier curve comes in to the loop too much then the mesh will no longer follow the curve, and will cut across it.
As shown here. The red cylinder is the actual start of the loop and goes clockwise around the image
![alt text][1]
[1]: https://i.imgur.com/xAJjRxT.png
The way I am setting the triangles right now is setting opposites. So if the first point is 3 away from the start, then the second point would be 3 away from the end.
I am really not sure how to can fix this. Any ideas would be greatly appreciated.c#meshgenerationprocedural meshbezierWed, 26 Sep 2018 20:20:46 GMTMechaWolf99Vector2 calculate bezier anchor point based on vectors
http://answers.unity.com/questions/1536043/vector2-calculate-bezier-anchor-point-based-on-vec.html
I've spent some time trying to work out how to achieve the following but I am unsure of how to proceed.
Please see the attached image
Currently I am getting a bezier weighted on the anchor point **x** however the line does't appear to be perpendicular. On top of that when the vector between the two points is facing some directions **x** is calculated on top of or behind the starting vector.vector2bezierMon, 30 Jul 2018 12:20:12 GMTtypaneHow should i draw a bezier curve in a compute shader? (Already works in c#)
http://answers.unity.com/questions/1477964/how-should-i-draw-a-bezier-curve-in-a-compute-shad.html
Okay, so i've made this mess of c# code; it loops through all the pixels in the texture and and calculates the distance from points along the bezier curve (defined by vx and vy). This works fine in c#, but i'd like to convert it to shader-code for some added performance. However I am (clearly) not that great with computeshaders, and i cant wrap my head around what i'm missing...
EDIT: the values i used for the vectors were; 1=(0,0) 2=(0.5,1) 3=(1,0), and the precision is 100.
----------
Here is the c# code and the output it can produce, bear with me, I'm not too good at producing readable code;
using UnityEngine;
public class DrawOnTex : MonoBehaviour
{
public int width = 256;
public int height = 256;
Vector2 vec1;
Vector2 vec2;
Vector2 vec3;
public Transform t1;
public Transform t2;
public Transform t3;
public int perlinSize = 10;
public int precision = 10;
Renderer r;
#region valueCheckers
int oldW;
int oldH;
Vector2 oldV1;
Vector2 oldV2;
Vector2 oldV3;
int oldPr;
bool ValuesChanged()
{
bool dimensionsMatch = (width == oldW && height == oldH);
bool vectorsMatch = (vec1 == oldV1 && vec2 == oldV2 && vec3 == oldV3);
bool othersMatch = (precision == oldPr);
//Debug.Log(dimensionsMatch +" "+ vectorsMatch + " " + othersMatch);
return !(dimensionsMatch && vectorsMatch && othersMatch);
}
#endregion
private void Start()
{
r = GetComponent<Renderer>();
}
private void Update()
{
PlaceVectors();
if (ValuesChanged())
{
r.material.mainTexture = GenerateTex();
//Debug.Log("generated");
}
oldW = width;
oldH = height;
oldV1 = vec1;
oldV2 = vec2;
oldV3 = vec3;
oldPr = precision;
}
void PlaceVectors()
{
vec1 = t1.position;
vec2 = t2.position;
vec3 = t3.position;
}
RenderTexture GenerateTexCompute()
{
RunShader();
return rTex;
}
Texture2D GenerateTex()
{
Texture2D tex = new Texture2D(width, height);
Color[] values = new Color[width * height];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
Color col = BezierCalc(vec1, vec2, vec3, x, y);
values[y * height + x] = col;
}
}
tex.SetPixels(values);
tex.Apply();
tex.filterMode = FilterMode.Point;
return tex;
}
Color BezierCalc(Vector2 a, Vector2 b, Vector2 c, int x, int y)
{
float xCoord = (float)x / width;
float yCoord = (float)y / height;
float v = 10000;
for (int i = 0; i < precision; i++)
{
float t = (float)i / precision;
float vx = a.x - 2 * t * a.x + (t * t) * a.x + 2 * t * b.x - 2 * (t * t) * b.x + (t * t) * c.x;
float vy = a.y - 2 * t * a.y + (t * t) * a.y + 2 * t * b.y - 2 * (t * t) * b.y + (t * t) * c.y;
Vector2 bz = new Vector2(vx, vy);
Vector2 xy = new Vector2(xCoord, yCoord);
float l = (bz - xy).magnitude;
v = Mathf.Min(v, l);
}
return new Color(v, v, v, 1);
}
}
![alt text][1]
----------
And here is the compute shader code and its output;
using UnityEngine;
public class DrawOnTex : MonoBehaviour
{
public int width = 256;
public int height = 256;
Vector2 vec1;
Vector2 vec2;
Vector2 vec3;
public Transform t1;
public Transform t2;
public Transform t3;
public int perlinSize = 10;
public int precision = 10;
Renderer r;
RenderTexture rTex;
#region ComputeshaderTest
public ComputeShader shader;
void RunShader()
{
int kernel = shader.FindKernel("CSMain");
shader.SetTexture(kernel, Shader.PropertyToID("Result"), rTex);
shader.SetFloat("width", width);
shader.SetFloat("height", height);
shader.SetVector("a", vec1);
shader.SetVector("b", vec2);
shader.SetVector("c", vec3);
shader.SetInt("p", precision);
shader.Dispatch(kernel, width, height, 1);
}
#endregion
#region valueCheckers
int oldW;
int oldH;
Vector2 oldV1;
Vector2 oldV2;
Vector2 oldV3;
int oldPr;
bool ValuesChanged()
{
bool dimensionsMatch = (width == oldW && height == oldH);
bool vectorsMatch = (vec1 == oldV1 && vec2 == oldV2 && vec3 == oldV3);
bool othersMatch = (precision == oldPr);
//Debug.Log(dimensionsMatch +" "+ vectorsMatch + " " + othersMatch);
return !(dimensionsMatch && vectorsMatch && othersMatch);
}
#endregion
private void Start()
{
r = GetComponent<Renderer>();
rTex = new RenderTexture(width, height, 0);
rTex.enableRandomWrite = true;
rTex.Create();
}
private void Update()
{
PlaceVectors();
if (ValuesChanged())
{
r.material.mainTexture = GenerateTexCompute();
Debug.Log("generated");
}
oldW = width;
oldH = height;
oldV1 = vec1;
oldV2 = vec2;
oldV3 = vec3;
oldPr = precision;
}
void PlaceVectors()
{
vec1 = t1.position;
vec2 = t2.position;
vec3 = t3.position;
}
RenderTexture GenerateTexCompute()
{
RunShader();
return rTex;
}
}
And the shader code itself;
#pragma kernel CSMain
RWTexture2D<float4> Result;
float width;
float height;
float2 a;
float2 b;
float2 c;
int p = 10;
[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
float xCoord = id.x / width;
float yCoord = id.y / height;
float v = 10000;
for (int i = 0; i < p; i++)
{
float t = i / (uint)p;
float vx = a.x - 2 * t * a.x + (t * t) * a.x + 2 * t * b.x - 2 * (t * t) * b.x + (t * t) * c.x;
float vy = a.y - 2 * t * a.y + (t * t) * a.y + 2 * t * b.y - 2 * (t * t) * b.y + (t * t) * c.y;
float2 bz = float2(vx, vy);
float2 xy = float2(xCoord, yCoord);
float l = length((bz-xy));
v = min(v, l);
}
Result[id.xy] = float4(v,v,v,1);
}
Btw, the result from the computeshader isnt inverted as the c# example is.
![alt text][2]
----------
[1]: /storage/temp/112615-aaaplz0.png
[2]: /storage/temp/112616-aaaplz1.pngc#distanceconversioncompute shaderbezierThu, 08 Mar 2018 20:50:09 GMTkalledk21Making a realistic breaking wave
http://answers.unity.com/questions/1457668/making-a-realistic-breaking-wave.html
Hey there,
<br>
Just looking for some pointers into making a realistic surfable wave in C#. I've got a procedurally generated plane at the moment and have been experimenting with deforming the mesh in a similar fashion to [this tutorial][1] by cat like coding.
<br>
I would like to achieve an effect similar to [MegaFiers bezier attractor][2] however would prefer to develop this myself instead of investing hundreds in a mesh deformation system for just one of its functions. If anyone can point me in the right direction that would be greatly appreciated.
<br>
Thanks in advance!
[1]: http://catlikecoding.com/unity/tutorials/mesh-deformation/
[2]: https://www.youtube.com/watch?v=_sFCPfc7mDUmeshproceduralprocedural-generationdeformationbezierSun, 21 Jan 2018 00:26:07 GMTGreenieHow can I import dupliframes from blender?
http://answers.unity.com/questions/1426844/how-can-i-import-dupliframes-from-blender.html
I'm trying to export x number of points along a bezier curve as objects in Unity (Think waypoints on a racetrack defined by the curve). I've tried using dupliframes to make duplicate empty objects along the curve. This seems to work how I want, except that while all the objects are exported into unity, they are all placed at the same point based on the curve's evaluation time. Selecting "Make Duplicates Real" fixes that problem, but it essentially stops me from further editing the curve without completely redoing the whole process.
Am I on the right track, or is there a better way to achieve the same result? The only other solution I've come up with is to create x number of empty objects and manually set their position along the curve with a Follow Path constraint, which isn't particularly efficient and seems like a pain if I decide to change the number of points.blenderexportcurvewaypointsbezierSat, 28 Oct 2017 02:41:52 GMTianlarsonFinding the next point on a Bezier Curve with Vector3's
http://answers.unity.com/questions/1390096/finding-the-next-point-on-a-bezier-curve-with-vect.html
I'm creating a bouncing game where the objective is to catch a falling ball going from one point to another, I'm not using physics for the bouncing effect, instead of I'm using a bezier curve to simulate the angle.
The way it's getting calculated is I'm using four Vector3's. p0 through p3
p0 will be the balls current transform.position, easy enough (example: -2.5, 0, 0).
p2 will be the **intercept** point, it is at this point where you're able to catch the ball, we know that as well. (2.5, 0, 0)
p1 we can figure out because we're specifying a y, value, and the x value you will be the position between p0 and p2. ((2.5 + -2.5)/2, 2.5, 0) or (0, 2.5, 0)
But where I'm getting hung up is what the value of p3 should be. Again, we're setting a static y value, no issue there. But I can't figure out how to get **x**. I know that in this example it's going to be 5, because that's the next logical step, but I don't know the math to get 5. The point of this step is just to have the ball keep falling past the play area naturally
The ball's x position can be other values besides 2.5, sometimes the ball will bounce in place. (So p2 would also be (-2.5, 0, 0)) and I think that's throwing a wedge into the math I'm trying to figure out.
I've attached an image of what I'm trying to accomplish.
![alt text][1]
[1]: /storage/temp/99321-curve-math.jpgvector3transform.positionbezierSun, 06 Aug 2017 18:12:04 GMThozthemageHow move object on Bezier path?
http://answers.unity.com/questions/1379492/how-move-object-on-bezier-path.html
I managed to implement the Bezier algorithm, now I wanted to use it in the update to do iteration of movement for a path. In this case, should I change the operation? I do not like sliding nodes in Update()
private Vector3 Bezier(float t, Vector3 p0, Vector3 p1, Vector3 p2)
{
float u = 1 - t;
float tt = t * t;
float uu = u * u;
Vector3 p = uu * p0;
p += 2 * u * t * p1;
p += tt * p2;
return p;
}
private void Update()
{
for (int point = 0; point < path.Length - 2; point +=2)
{
curr += Time.deltaTime;
perc = curr / 10f;
tr.transform.position = Bezier(perc, path[point].position, path[point + 1].position, path[point + 2].position);
}
}movementupdatepathinterpolationbezierSat, 15 Jul 2017 17:10:26 GMTBoltCorrect normals on a cylindrical rail (hairy ball theorem)
http://answers.unity.com/questions/1320787/correct-normals-on-a-cylindrical-rail-hairy-ball-t.html
According to the Hairy Ball theorem, it is not possible to get consistently oriented normals at any point on the curve.
What I want to achieve is a game object moving beneath a procedurally-generated rail (plain cylinder). To generate a tube I use a spline which consists of bezier curves. Thus, I need to get a correctly oriented normals at any point of the curve.
The code looks like this:
Vector3 q2 = GetCurveTangent (...);
Quaternion lookAt = Quaternion.LookRotation (q2);
Vector3 normal = lookAt * Vector3.up;
normal = Quaternion.AngleAxis (angle, q2) * normal;
return point + normal * size;
Which generates the following normals:
![alt text][1]
On horizontal segments everything is correct, but on vertical ones, when tangent is oriented like Vector3.up, everything goes wrong.
The only advice I've received is to try and use the previous tangent instead of global up vector. But I can not get any good result out of it. What I tried to do is:
Quaternion lookAt = Quaternion.LookRotation (q2, previousNormal);
but it is not clear what to place here:
Vector3 normal = lookAt * ?
And any combination of tangent, normal and rotation gives me something like this:
![alt text][2]
So, the question is: how can one create a cylindrical rail and an object moving beneath it (using the normal facing strictly down the curve)? If curve is vertical, "down" is of course globally forward and so on.
[1]: /storage/temp/89203-y45kr.png
[2]: /storage/temp/89204-7ocva.pngnormalsprocedural generationsplinecurvesbezierSun, 05 Mar 2017 15:27:30 GMTsmslvHow to get lateral normals of a bezier curve
http://answers.unity.com/questions/1292624/how-to-get-lateral-normals-of-a-bezier-curve.html
Hi guys, first of all, I apologize for my bad english, it's not my first language. So, I've made my own bezier spline script and I'm working on things like "spline follower, and a script to spawn objects along the spline. But I got two problems.
1.The first is: The objects that follows the spline are moving with a unstable speed, (I know, a bezier curve has different velocities) but, can I do something to make the objects follow the spline in a stable speed? I've been looking for an answer for this all over the Internet but yet, came up with nothing.
2.The second problem is: Like I said, I'm working on a script to spawn objects along the spline, and the objects have to face the center of the spline (Like a fence, "looking forward"), so I tried to make the rotation of each instanced object equal to "BezierSpline.GetTangent();" and "BezierSpline.GetDirection" but none of them worked, the objects always get a weird rotation, and I've been thinking, if I get the inside normals of the curve, and set them as the rotation using "LookAt(normals) for example" maybe it works, but I have no idea of how to get the inside normals. My current script can only give me normals looking to Vector3.up.
Like this: (Green Lines are normals).
![alt text][1]
But I actually need this (Red lines):
![alt text][2]
So, can anyone help me please? Tell me if I wasn't clear enough.
[1]: /storage/temp/85052-screenshot-27.png
[2]: /storage/temp/85053-orla8.jpgc#programmingmathcurvebezierSun, 01 Jan 2017 17:30:28 GMTyoneclick[Vectrosity] 3d bezier curve not generated correctly
http://answers.unity.com/questions/1279062/vectrosity-3d-bezier-curve-not-generated-corretly.html
Hello,
I'm trying to draw a 3D bezier curve with Vectrosity (in order to create a 3D selection arrow). If the curve is aligned with the Y-axis, then the result looks as expected (red curve), but any other alignment makes the segments of the curve visible and also introduces some glitches at the start and the end (black curve). Any idea why is this happening?
// Black curve (bad).
VectorLine vl = new VectorLine(
"vl0",
new List<Vector3>() { Vector3.zero, Vector3.zero },
30.0f);
vl.lineType = LineType.Continuous;
vl.Resize( 111 );
vl.MakeCurve(
Vector3.zero,
new Vector3( .0f, .0f, -1.0f ),
new Vector3( -3.0f, .0f, .0f ),
new Vector3( -3.0f, .0f, -1.0f ),
110 );
vl.Draw3D();
vl.color = Color.black;
// Red curve (good!).
vl = new VectorLine(
"vl1",
new List<Vector3>() { Vector3.zero, Vector3.zero },
30.0f);
vl.lineType = LineType.Continuous;
vl.Resize( 111 );
vl.MakeCurve(
Vector3.zero,
new Vector3( .0f, .0f, -1.0f ),
new Vector3( .0f, 3.0f, .0f ),
new Vector3( .0f, 3.0f, -1.0f ),
110 );
vl.Draw3D();
vl.color = Color.red;
![alt text][1]
[1]: /storage/temp/83186-vectrosity-bezier-00.png3dcurvevectrositybezierSat, 03 Dec 2016 07:41:23 GMTJonAMleantween ltspline control points setup
http://answers.unity.com/questions/1261116/leantween-ltspline-control-points-setup.html
Hi,
I have a custom curve in unity, made with the simple bezier asset package.
from this curve, i attempted to construct a spline, useable with the leantween package.
however, it seems the control points in my spline aren't working properly, or i'm doing something wrong.
the spline is setup like this: Vector3[] {h0, p0, p1, p2, h2}, as said in the documentation.
yet it the object that is meant to follow this spline only goes through te points, and does not follow the curve.
are the control points vectors just position, or do i have to adjust them in order to get the curve right?
the documentation says i need a tangent in those control points, but that's all it says. can anyone clearify this for me?c#splinebeziertweentweeningSun, 23 Oct 2016 16:52:29 GMTgluckezHow to draw bezier curve with mesh around it between 2 gameobjects
http://answers.unity.com/questions/1257198/how-to-draw-bezier-curve-with-mesh-around-it-betwe.html
i wanted to create curve line between 2 game objects. i tried alot of codes but for bezier curve we need more than 2 points. is there anyway i could do it with 2 points. the link i shared shows what i want.
https://www.youtube.com/watch?v=YYrLBzmFEjE
Will be thankfull if someone responds.linecurvebezierSun, 16 Oct 2016 16:02:15 GMTz33shan4liBezier Spline Road Issues
http://answers.unity.com/questions/1240874/bezier-spline-road-issues.html
G'day guys.
I'm stuck with scaling multiple duplicates of a gravel road model on a Bezier spline (the code was from this website: http://catlikecoding.com/unity/tutorials/curves-and-splines/). When I enter play mode, Unity currently instantiates the models without scaling to size as shown below.
![alt text][1]
[1]: /storage/temp/77868-gravelroad2.png
Any help fixing the gaps in the road would be appreciated.c#3dsplinebezierroadThu, 08 Sep 2016 12:48:35 GMTNeedNewUsernameDrawing random paths with quadratic bezier curves
http://answers.unity.com/questions/1238197/drawing-random-paths-with-quadratic-bezier-curves.html
I want to draw smooth* and random paths that my objects would follow and I decided to go with quadratic bezier curves (but I'm open to other ideas).
My code is moving my objects in a random, but not smooth* way.
Preview: https://youtu.be/Eg9PEKuH4zA
My question is: how can I make the direction changes smoother? Should I completely ditch my Bezier solution or is there a way I could polish my code to achieve what I want?
*smooth == no abrupt direction changes
My code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Lights : MonoBehaviour {
public float paintHeight = -90.0f;
public static int NUMBER_OF_LIGHTS = 3;
private static int BEZIER_PATH_POINTS = 100;
private float GOLDEN_COLOR_RATIO = 0.618033988749895f;
private Light[] lights = new Light[NUMBER_OF_LIGHTS];
Vector3 RandomPoint() {
float obj_width = gameObject.GetComponent<RectTransform>().rect.width;
float screenX = Random.Range(-obj_width / 2, obj_width / 2);
float obj_height = gameObject.GetComponent<RectTransform>().rect.height;
float screenY = Random.Range(-obj_height / 2, obj_height / 2);
return new Vector3(screenX, screenY, -paintHeight);
}
Vector3 QuadraticBezierPoint(Vector3 startPoint, Vector3 endPoint, Vector3 vertexPoint, float t) {
/*
* vertex
* /╲
* / ╲
* / p ╲
* / . . ╲
* / . · ╲
* /· · ╲
* start · end
*
* 0 < t < 1
*
* B(t) = (1 - t)^2 * P0 + 2 * (1-t) * t * P1 + t^2 * P2
*
*/
return Mathf.Pow((1 - t), 2) * startPoint + 2 * (1 - t) * t * vertexPoint + Mathf.Pow(t, 2) * endPoint;
}
Color RandomColor() {
float h = Random.Range(0.0f, 1.0f) + GOLDEN_COLOR_RATIO;
h %= 1;
return Color.HSVToRGB(h, 0.99f, 0.99f);
}
void Start() {
for (int i = 0; i < NUMBER_OF_LIGHTS; i++) {
GameObject light_obj = new GameObject();
Light light = light_obj.AddComponent<Light>();
light.type = LightType.Point;
light.range = 10.0f;
light.intensity = 3.5f;
light.renderMode = LightRenderMode.ForcePixel;
light.name = "Light" + i;
light.transform.parent = gameObject.transform;
lights[i] = light;
}
StartCoroutine("Move");
}
IEnumerator Move () {
Dictionary<string, Vector3>[] light_points = new Dictionary<string, Vector3>[NUMBER_OF_LIGHTS];
Dictionary<string, Color>[] light_colors = new Dictionary<string, Color>[NUMBER_OF_LIGHTS];
for (int i = 0; i < NUMBER_OF_LIGHTS; i++) {
light_points[i] = new Dictionary<string, Vector3>();
light_colors[i] = new Dictionary<string, Color>();
//light_points[i]["startPoint"] = RandomPoint();
//light_points[i]["vertexPoint"] = RandomPoint();
light_points[i]["endPoint"] = RandomPoint();
light_colors[i]["nextColor"] = RandomColor();
}
while(true) {
for (int i = 0; i < NUMBER_OF_LIGHTS; i++) {
light_points[i]["startPoint"] = light_points[i]["endPoint"];
light_points[i]["vertexPoint"] = RandomPoint();
light_points[i]["endPoint"] = RandomPoint();
light_colors[i]["currentColor"] = light_colors[i]["nextColor"];
light_colors[i]["nextColor"] = RandomColor();
}
for (int i = 0; i < BEZIER_PATH_POINTS; i++) {
float percent = (float)i / BEZIER_PATH_POINTS;
for (int j = 0; j < NUMBER_OF_LIGHTS; j++) {
lights[j].transform.localPosition = QuadraticBezierPoint(
light_points[j]["startPoint"],
light_points[j]["endPoint"],
light_points[j]["vertexPoint"],
percent
);
lights[j].color = Color.Lerp(light_colors[j]["currentColor"], light_colors[j]["nextColor"], percent);
}
yield return new WaitForSeconds(0.02f);
}
}
}
}randompathbezierFri, 02 Sep 2016 13:50:34 GMTalexandernstCoroutine for moving lights pauses after each iteration
http://answers.unity.com/questions/1237844/coroutine-for-moving-lights-pauses-after-each-iter.html
I have a few lights generated in my `Start()`. Once all lights are generated and assigned colors, range, intensity, etc... I call a coroutine that moves those lights. The coroutine looks like this:
Vector3 RandomPoint() {
float screenX = Random.Range(0.0f, Camera.main.pixelWidth);
float screenY = Random.Range(0.0f, Camera.main.pixelHeight);
//float ScreenZ = Random.Range(Camera.main.nearClipPlane, Camera.main.farClipPlane);
return Camera.main.ScreenToWorldPoint(new Vector3(screenX, screenY, paintHeight));
}
Vector3[] BezierPath(Vector3 startPoint, Vector3 endPoint) {
float distance = Vector3.Distance(startPoint, startPoint);
Vector3 startTangent, endTangent;
if (startPoint.x < endPoint.x) {
startTangent = startPoint + Vector3.right * (distance / 3f);
endTangent = endPoint + Vector3.left * (distance / 3f);
} else {
startTangent = startPoint + Vector3.left * (distance / 3f);
endTangent = endPoint + Vector3.right * (distance / 3f);
}
return Handles.MakeBezierPoints(startPoint, endPoint, startTangent, endTangent, BEZIER_PATH_POINTS);
}
IEnumerator Move () {
print("Moving...");
Vector3[][] light_points = new Vector3[NUMBER_OF_LIGHTS][];
Vector3[][] light_paths = new Vector3[NUMBER_OF_LIGHTS][];
for (int i = 0; i < NUMBER_OF_LIGHTS; i++) {
light_points[i] = new Vector3[2];
//light_points[i][0] = RandomPoint();
light_points[i][1] = RandomPoint();
}
while(true) {
System.DateTime d1 = System.DateTime.Now;
for (int i = 0; i < NUMBER_OF_LIGHTS; i++) {
light_points[i][0] = light_points[i][1];
light_points[i][1] = RandomPoint();
light_paths[i] = BezierPath(light_points[i][0], light_points[i][1]);
}
System.DateTime d2 = System.DateTime.Now;
print("Calc " + (d2 - d1).TotalMilliseconds + "ms");
for (int i = 0; i < BEZIER_PATH_POINTS; i++) {
for (int j = 0; j < NUMBER_OF_LIGHTS; j++) {
lights[j].transform.position = light_paths[j][i];
}
if (i + 1 < BEZIER_PATH_POINTS) {
yield return new WaitForSeconds(0.02f);
}
}
print("End");
}
}
The problem is that after each iteration of the `while` loop the lights stop moving for a noticeable amount of time. I thought that it might be caused by the first `for` loop inside the while, which calls an expensive function (`MakeBezierPoints`) multiple times, but the time diff shows that that piece of code takes barely 50ms.
What is causing that pause? How could I move my lights without any noticeable pauses?coroutinemove an objectbezierThu, 01 Sep 2016 09:13:15 GMTalexandernstExtrude shape with sharp corners
http://answers.unity.com/questions/1236197/extrude-shape-with-sharp-corners.html
Hi all!
I am to extrude a shape "linearily", that is if there is a 90 degree corner i want the corner to be sharp, the same described in this page: http://blender.stackexchange.com/questions/19709/extrude-along-path-sharp-corners. I've looked at the tutorial about the [procedural geometry generetion][1] but this doesnt solve the problem for sharp corners.
Is there anyone with any tips on how to solve this?
Best regards
Joel
[1]: https://www.youtube.com/watch?v=o9RK6O2kOKomeshprocedural meshbezierMon, 29 Aug 2016 13:43:30 GMTjoelolofssonProcedural mesh, using beziers for walls and roads
http://answers.unity.com/questions/1219551/procedural-mesh-using-beziers-for-walls-and-roads.html
Hello. I have been trying to make a system for creating procedural walls (and roads) using beziers. Something something along the lines of the road system in Cities Skylines. My first idea was to use premade geometry and instantiate wallsegments at fixed intervals. But since i want to have the walls join at points on towers and buildings, the length of the walls has to be very precise.
So I have been looking at procedural meshes and bezier splines and after scouring the web, I kindof made a somewhat usable piece of code. The tutorials I have found have been very specific and I am just not experianced enough with coding to be able to figure this out.
https://drive.google.com/folderview?id=0B4S0tkWTFjF3YjU0T2piZVM0eHM&usp=sharing Here is a link to the unity project.
Below I have posted the code i have stitched together from bits and pieces found on the web and altered to be somewhat consistent...
When the mouse is clicked you can drag the cursor to create a line of verticies. If shift is held down the wall can be curved. I can alter the height of the wall by adding more segments in the Y direction. The cursor snaps to the closest end point of existing walls.
But now I am lost. Adding triangles in a loop to the verticies is a nightmare. And how do i offset the verticies from the center of the line, and set their rotation to fit the curvature and direction of the wall?
I hope someone can help me. If you can point me to some other way to create procedural walls at runtime, that would be allso be fantastic. I have found several eksamples of this, but no tutoruals. I am so close! :)
http://architred.blogspot.dk/2013/05/unity-wall-tool.html <-- this guy made it
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
public class NewWall : MonoBehaviour
{
bool creating;
public GameObject start;
public GameObject end;
public GameObject bezier;
public GameObject adfa;
public LayerMask wallLayer;
public GameObject wallPolePoint;
public int WallHeight = 3;
bool poleSnapping;
bool endPoleSnapping;
bool isCurving;
List<GameObject> poles;
// Use this for initialization
void Start()
{
poles = new List<GameObject>();
}
// Update is called once per frame
void Update()
{
startCursor();
getInput();
}
Vector3 getWorldPoint()
{
Ray ray = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, ~wallLayer))
{
return hit.point;
}
return Vector3.zero;
}
void getInput()
{
end.SetActive(false);
bezier.SetActive(false);
if (Input.GetMouseButtonDown(0))
{
setStart();
end.SetActive(true);
bezier.SetActive(true);
}
if (Input.GetKeyDown(KeyCode.LeftShift))
{
setBezier();
isCurving = true;
}
if (Input.GetKeyUp(KeyCode.LeftShift))
{
isCurving = false;
}
else if (Input.GetMouseButtonUp(0))
{
setEnd();
StartCoroutine(createWallSegments());
isCurving = false;
}
else
{
if (creating)
{
adjust();
end.SetActive(true);
bezier.SetActive(true);
}
}
}
Vector3 gridSnap(Vector3 originalPosition)
{
int granularity = 1;
Vector3 snappedPosition = new Vector3(Mathf.Floor((originalPosition.x / granularity) * granularity), originalPosition.y, Mathf.Floor(originalPosition.z / granularity) * granularity);
return snappedPosition;
}
void startCursor()
{
if (creating)
{
adjust();
}
else
{
if (GameObject.FindGameObjectsWithTag("Pole").Length == 0)
{
start.transform.position = gridSnap(getWorldPoint());
poleSnapping = false;
}
else if
(Vector3.Distance((getWorldPoint()), closestPoleTo(getWorldPoint()).transform.position) <= 5)
{
start.transform.position = closestPoleTo(getWorldPoint()).transform.position;
poleSnapping = true;
}
else
{
start.transform.position = gridSnap(getWorldPoint());
poleSnapping = false;
}
}
}
void setStart()
{
creating = true;
start.transform.position = gridSnap(getWorldPoint());
if (poleSnapping)
{
start.transform.position = closestPoleTo(getWorldPoint()).transform.position;
}
GameObject p1 = (GameObject)Instantiate(wallPolePoint, start.transform.position, start.transform.rotation);
p1.tag = "Pole";
poles.Add(p1);
}
void setEnd()
{
creating = false;
end.transform.position = gridSnap(getWorldPoint());
if (endPoleSnapping)
{
end.transform.position = closestPoleTo(getWorldPoint()).transform.position;
}
GameObject p2 = (GameObject)Instantiate(wallPolePoint, end.transform.position, end.transform.rotation);
p2.tag = "Pole";
poles.Add(p2);
}
void setBezier()
{
creating = true;
bezier.transform.position = gridSnap(getWorldPoint());
}
GameObject closestPoleTo(Vector3 worldPoint)
{
GameObject closest = null;
float distance = Mathf.Infinity;
float currentDistance = Mathf.Infinity;
foreach (GameObject p in poles)
{
currentDistance = Vector3.Distance(worldPoint, p.transform.position);
if (currentDistance < distance)
{
distance = currentDistance;
closest = p;
}
}
return closest;
}
void adjust()
{
if (GameObject.FindGameObjectsWithTag("Pole").Length == 0)
{
end.transform.position = gridSnap(getWorldPoint());
endPoleSnapping = false;
}
else if
(Vector3.Distance((getWorldPoint()), closestPoleTo(getWorldPoint()).transform.position) <= 5)
{
end.transform.position = closestPoleTo(getWorldPoint()).transform.position;
endPoleSnapping = true;
}
else
{
end.transform.position = gridSnap(getWorldPoint());
endPoleSnapping = false;
}
adjustWall();
}
void adjustWall()
{
Vector3 endTargetPostition = new Vector3(end.transform.position.x, start.transform.position.y, end.transform.position.z);
Vector3 startTargetPostition = new Vector3(start.transform.position.x, end.transform.position.y, start.transform.position.z);
start.transform.LookAt(endTargetPostition);
end.transform.LookAt(startTargetPostition);
Vector3 Distance = (start.transform.position + end.transform.position) / 2f;
if (isCurving == false)
{
bezier.transform.position = Distance;
}
}
//---------------------------------------------------------------------
//this is the mesh generation code
//---------------------------------------------------------------------
List<Vector3> vertices = new List<Vector3>();
private IEnumerator createWallSegments()
{
WaitForSeconds wait = new WaitForSeconds(0.05f);
Mesh mesh = new Mesh();
float distance = Mathf.Floor(Vector3.Distance(start.transform.position, end.transform.position) / 2);
int distanceInt = Convert.ToInt32(distance);
// set points of quadratic Bezier curve
Vector3 p0 = start.transform.position;
Vector3 p1 = bezier.transform.position;
Vector3 p2 = end.transform.position;
float t;
Vector3 position;
for (int i = 0, x = 0; x <= distance; x++)
{
for (int y = 0; y < WallHeight; y++, i++)
{
t = x / (distance);
position = (1.0f - t) * (1.0f - t) * p0 + 2.0f * (1.0f - t) * t * p1 + t * t * p2;
Vector3 newPos = new Vector3(position.x, position.y + y, position.z);
vertices.Add(newPos);
yield return wait;
}
}
mesh.vertices = vertices.ToArray();
Debug.Log(mesh.vertices.Length);
//List<int> triangles = new List<int>(mesh.triangles);
int[] triangles = new int[mesh.vertices.Length * 6];
for (int ti = 0, vi = 0, x = 0; x < WallHeight; x++, ti += 6, vi++)
{
triangles[ti] = vi;
triangles[ti + 3] = triangles[ti + 1] = vi + 1;
triangles[ti + 2] = triangles[ti + 5] = vi + WallHeight;
triangles[ti + 4] = vi + WallHeight + 1;
}
//I am able to make the first row, but I am at a loss on how to loop this code. Everything I have tryed have
//resultet in some strange behavior, with missing quads, half the wall facing the wrong way, or triangles joining
// verts on the far side of the wall..
mesh.triangles = triangles;
//mesh.triangles = triangles.ToArray();
MeshFilter filter = GetComponent<MeshFilter>();
if (filter != null)
{
filter.sharedMesh = mesh;
}
}
private void OnDrawGizmos()
{
if (vertices == null)
{
return;
}
Gizmos.color = Color.black;
for (int i = 0; i < vertices.Count; i++)
{
Gizmos.DrawSphere(vertices[i], 0.1f);
}
}
}procedural meshwallsbezierroadsFri, 22 Jul 2016 17:18:56 GMT-OTTO-Bezier curves with rotation
http://answers.unity.com/questions/1182440/bezier-curves-with-rotation.html
Hi guys. I have a quick question for you. I have a character and i want to move it along a bezier curve. I have found a few solution but none of them allowed me to rotate the player along the curve. Can you help me ? Thank you.rotationcurvebezierFri, 06 May 2016 16:43:10 GMTiubisoftspline controller system + rotation
http://answers.unity.com/questions/1179141/spline-controller-system-rotation.html
hi, im using the spline controller system ( http://goo.gl/rnD28O ).
then rotation script ( http://goo.gl/JnDpEV )
assigned to gameobject as child of "spline system follower".
when its global direction is constant, rotation works fine.
but when direction of follower changes(cuz of waypoint nodes' placements)
rotation goes crazy and loses the rotation script control.
i was using parent-child system to set the pivot point
of rotation (using localRotation in script). you guys have any idea why it happens?
is there a proper way to use rotation on a waypoint following
object?rotationbezierSun, 01 May 2016 05:31:13 GMTstnmycrDraw Curve on texture in Unity
http://answers.unity.com/questions/1173196/draw-curve-on-texture-in-unity.html
I want to draw curve on texture using bezier curves basically what am trying to do is create jigsaw puzzle pieces shapes at runtime . Any help would be appreciatedunity 5textureruntimebezierTue, 19 Apr 2016 04:49:15 GMTawais_1304Offset curve line Vectrosity
http://answers.unity.com/questions/1163674/offset-curve-line-vectrosity.html
I'm trying to draw lines with offset to main line like on attachment.
![offset curve lines][2]
I have problems with my code. It generating crosses on the lines if curve is small. (attachment)![alt text][1]
Maybe someone can help me with this code or know any good algorithm to generate curved lines with offset
// LEFT SIDE OF MAIN LINE
int numberOfLines = 10;
float offset = 10f;
lastLinePoints = outerPoints; // outerPoint = Points from Main Line
for(int i = 0; i < numberOfLines; i++)
{
List<Vector3> tempPoints = new List<Vector3> ();
for (int k = 0; k < lastLinePoints.Count; k++) {
if (k + 1 < lastLinePoints.Count) {
Vector3 direction = lastLinePoints [k + 1] - lastLinePoints [k];
// up direction:
Vector3 up = new Vector3(0.0f, 1.0f, 0.0f);
// find right vector:
Vector3 right = Vector3.Cross(direction.normalized, up.normalized);
Vector3 newPoint = lastLinePoints [k] + (right * offset);
tempPoints.Add (newPoint);
}
}
VectorLine lineTemp = new VectorLine ("lineCurved", tempPoints, 120f / _camera2DObject.GetComponent<Camera> ().orthographicSize, LineType.Continuous);
lineTemp.Draw3D ();
lastLinePoints = tempPoints;
}
[1]: /storage/temp/67052-screen-shot-2016-03-31-at-201018.png
[2]: /storage/temp/67048-screen-shot-2016-03-31-at-193026.pngoffsetlinesvectrositybezierThu, 31 Mar 2016 17:39:09 GMTmaciekfreak