How do i add lines to end Cubes??
Hello i am having some trouble trying to do this in Pic1, but i am having a hard time in doing it, i tried using Modulo but i could not get the objects positions so i could not finish the process, does anyone know how to do this?
-Pic1
Here is the (functioning)code i am trying to implement it to
public class roundedSpline : MonoBehaviour
{
[System.Serializable]
public class SplinePoint
{
public Transform t;
public Transform cpAhead;
public Transform cpBehind;
public int seg;
public SplinePoint(Transform thetrans, Transform a, Transform b, int s)
{
t = thetrans;
cpAhead = a;
cpBehind = b;
seg = s;
}
}
public List<Transform> controlPointsList;
public List<SplinePoint> splinePoints;
public Transform segment;
public int segCount = 2;
public float updateRate = 60f;
public bool setup = false;
public bool running = false;
void Start()
{
splinePoints = new List<SplinePoint>();
CreateObjects(segment);
}
public void CreateObjects(Transform original)
{
for (int i = 0; i < controlPointsList.Count - 1; i++)
{
for (int j = 0; j < segCount; j++)
{
var a = Instantiate(original, Vector3.zero, Quaternion.identity) as Transform;
splinePoints.Add(new SplinePoint(a.transform, controlPointsList[i + 1], controlPointsList[i], j));
}
}
setup = true;
}
void Update()
{
if (setup && !running)
{
UpdateSplinePos();
}
}
void UpdateSplinePos()
{
for (int i = 0; i < splinePoints.Count; i++)
{
SetPosition(splinePoints[i]);
}
}
SplinePoint GetSplinePoint(int s)
{
SplinePoint sp = null;
if (splinePoints.Count > 0)
{
for (int i = 0; i < splinePoints.Count; i++)
{
if (splinePoints[i].seg == s)
{
sp = splinePoints[i];
break;
}
}
}
return sp;
}
void OnDrawGizmos()
{
Gizmos.color = Color.white;
for (int i = 0; i < controlPointsList.Count; i++)
{
Gizmos.DrawWireSphere(controlPointsList[i].position, 0.3f);
}
for (int i = 0; i < controlPointsList.Count - 1; i++)
{
Gizmos.DrawLine(controlPointsList[i].position, controlPointsList[i + 1].position);
}
}
void SetPosition(SplinePoint sp)
{
float dist = Vector3.Distance(sp.cpAhead.position, sp.cpBehind.position);
float step = dist / (segCount + 1);
Vector3 dir = (sp.cpAhead.position - sp.cpBehind.position).normalized;
sp.t.position = sp.cpBehind.position + ((dir * step) * (sp.seg + 1));
sp.t.rotation = Quaternion.LookRotation(dir);
}
}
capture48.png
(29.0 kB)
Comment
Best Answer
Answer by b1gry4n · Sep 03, 2016 at 06:13 AM
void OnDrawGizmos()
{
if (!setup)
{
return;
}
Gizmos.color = Color.white;
for (int i = 0; i < controlPointsList.Count; i++)
{
Gizmos.DrawWireSphere(controlPointsList[i].position, 0.3f);
}
for (int i = 0; i < controlPointsList.Count - 1; i++)
{
Gizmos.DrawLine(controlPointsList[i].position, controlPointsList[i + 1].position);
}
//Get a list of associated nodes relative to control point. We want the last of the current control point and the first of the next control point
Gizmos.color = Color.red;
for (int i = 0; i < controlPointsList.Count - 1; i++)
{
List<SplinePoint> associatedNodes = NodesAssociated(controlPointsList[i]);
List<SplinePoint> associatedNodesAhead = NodesAssociated(controlPointsList[i+1]);
if (associatedNodes.Count > 0 && associatedNodesAhead.Count > 0)
{
Gizmos.DrawLine(associatedNodes[associatedNodes.Count - 1].t.position, associatedNodesAhead[0].t.position);
}
}
}
List<SplinePoint> NodesAssociated(Transform behindNode)
{
List<SplinePoint> p = new List<SplinePoint>();
for (int i = 0; i < splinePoints.Count; i++)
{
if (splinePoints[i].cpBehind == behindNode)
{
p.Add(splinePoints[i]);
}
}
return p;
}
d.jpg
(30.8 kB)
Your answer
Follow this Question
Related Questions
How do i use lines to calculate triangles on mesh?? 0 Answers
The location of the object by points 0 Answers
How do i Gizmos.drawLines in an order?? 2 Answers
OnCollisionEnter not running. 1 Answer
How do i create Tangents on a spline?? 0 Answers