09-02-2021, 11:03 PM
Thank you for the help!
I removed the extra CP I accidentally added and am using Controller.Position += amount, it positions all of there spheres in the same place.
But the real problem is Spline.Length isn't 30 - you can see that on line 45 - Debug.LogWarning.
I removed the extra CP I accidentally added and am using Controller.Position += amount, it positions all of there spheres in the same place.
But the real problem is Spline.Length isn't 30 - you can see that on line 45 - Debug.LogWarning.
Code:
using FluffyUnderware.Curvy;
using FluffyUnderware.Curvy.Controllers;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class SplineTest : MonoBehaviour
{
// Start is called before the first frame update
private CurvySpline Spline;
private List<SplineFollower> Followers = new List<SplineFollower>();
void Start()
{
Spline = gameObject.AddComponent(typeof(CurvySpline)) as CurvySpline;
// Create Spline Followers\Controllers
for (int i = 0; i < 6; i++)
{
Followers.Add(new SplineFollower(Spline,i * 5));
}
Spline.Add(new Vector3(0, 0, 0));
Spline.Add(new Vector3(0, 0, 30));
}
// Update is called once per frame
void Update()
{
Spline.Clear();
// Create first Control point
Spline.Add(new Vector3(0, 0, 0));
//Create random number of control points
int rnd = Random.Range(1, 5);
for (int i = 1; i < rnd; i++)
{
Spline.Add(new Vector3(0, 0, i * 4.0f));
}
// Create last Control point
Spline.Add(new Vector3(0, 0, 30 - Spline.Length));
Debug.LogWarning(Spline.Length);
foreach (var item in Followers)
{
item.Move(0.1f);
}
}
public class SplineFollower
{
public SplineController Controller;
public float Position;
public SplineFollower(CurvySpline spline, float position)
{
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
Controller = go.AddComponent(typeof(SplineController)) as SplineController;
Controller.PositionMode = CurvyPositionMode.WorldUnits;
Controller.Spline = spline;
Position = position;
}
public void Move(float amount)
{
//Position += amount;
Controller.Position += amount;
}
}
}