Question by
Sylon87 · Sep 30, 2018 at 03:07 PM ·
linerendererlinecurveline rendererline drawing
issue with LineRender start from 0
hello. i'm trying to learn the bazier curve, by follow a tutoria, I do exactly the same things that I saw on the tutorial but I can't figure out why my curve is starting from 0.0 here is my code and my screen of unity.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bezier : MonoBehaviour
{
[SerializeField]
private LineRenderer lineRenderer;
[SerializeField]
private Transform point0,point1,point2;
private Vector3[] positions = new Vector3[50];
private int numOfPoints = 50;
// Use this for initialization
void Start ()
{
lineRenderer.positionCount = numOfPoints;
}
// Update is called once per frame
void Update ()
{
//DrawLinearCurve();
DrawQuadraticBazierCurve();
}
private void DrawQuadraticBazierCurve()
{
for (int i = 1; i < numOfPoints; i++)
{
float t = i / (float) numOfPoints;
positions[ i - 1] = CalculateQuadraticBezierPoint(t,point0.position,point1.position,point2.position);
}
lineRenderer.SetPositions(positions);
}
/*private Vector3 CalculateLinearBezierPoint (float t, Vector3 p0, Vector3 p1)
{
return p0 + t * (p1 - p0);
// P = P0 + t ( P1 - P0 )
}*/
private Vector3 CalculateQuadraticBezierPoint (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;
// B(t) = (1-t)2P0 + 2(1-t)tP1 + t2P2
}
someone can help me to figure out what i'm doing wrong?alt text
screen1.png
(328.7 kB)
screen2.png
(314.6 kB)
Comment
Your answer
Follow this Question
Related Questions
line render some lines not visible 2 Answers
Raycast line renderer not drawing correctly 0 Answers
How do I add points to a LineRenderer Width curve as I'm "drawing" the line? 0 Answers
LineRederer with corner vertices display positions in wrong location 0 Answers
How to draw bezier curve with mesh around it between 2 gameobjects 1 Answer