06-06-2014, 06:20 AM
In my project, I have a SplineGroup. I am trying to step along the spline when it is created, and generate objects along it. However, I need to find a way to 'step' forward properly on the spline. I'm currently using the following code to do so, and it eventually 'locks up', or refuses to move further ahead. Meaning it will spawn about 4 or 5 collectables just fine - then the remaining 25 or so all generate at the exact same position, which isn't even a quarter of the way through the spline path.
So based on this - what is the correct way to get a point X distance forward on the spline?
So based on this - what is the correct way to get a point X distance forward on the spline?
Code:
private void genCollectables()
{
Debug.Log("--- Gen Collectables Begun");
float genTF = 0.871f;
for(int i = 0; i < 30; i++)
{
Vector3 genPosition = movementPathSplineGroup.Interpolate(genTF);
GameObject tempColChain = (GameObject)Instantiate(tempPrefab);
// Set Position
tempColChain.transform.position = genPosition;
// Set rotation to match the spline
tempColChain.transform.rotation = movementPathSplineGroup.GetOrientationFast(genTF);
float distBetweenPoints = Mathf.Abs(genTF - genPosition);
genTF = tfAtLastPoint + distBetweenPoints;
}
}