08-31-2021, 07:31 PM
Ok so I was able to recreate it - you can attach this script to an empty game object.
If you look at line 44 "Spline.Add(new Vector3(0, 0, 30 - Spline.Length));" I'm attempting to use the current length of the spline to ensure the length is always 30.
If you change line 44 from
to
The issue goes away.
Any help much appreciated!
If you look at line 44 "Spline.Add(new Vector3(0, 0, 30 - Spline.Length));" I'm attempting to use the current length of the spline to ensure the length is always 30.
If you change line 44 from
Code:
Spline.Add(new Vector3(0, 0, 30 - Spline.Length));
Code:
Spline.Add(new Vector3(0, 0, 30));
The issue goes away.
Any help much appreciated!
Code:
using FluffyUnderware.Curvy;
using FluffyUnderware.Curvy.Controllers;
using System.Collections;
using System.Collections.Generic;
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();
Spline.Add(new Vector3(0, 0, 0));
// 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));
}
Debug.LogWarning($"SplineLength: {Spline.Length} LastCPZ: {Spline.LastSegment.transform.position.z}");
// Create last Control point
Spline.Add(new Vector3(0, 0, 30 - 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 = Position;
}
}
}