Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to find a point a distance ahead on the spline?
#1
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?


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;
}
}



 
Reply


Messages In This Thread
How to find a point a distance ahead on the spline? - by DCalabrese - 06-06-2014, 06:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting Distance from a World Point zorksox 3 5 04-16-2024, 07:30 PM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 3 6 04-04-2024, 12:56 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 6 03-28-2024, 10:08 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_

Forum Jump: