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
#2
Hi,

maybe you didn't post the whole code involved, but what I see makes no sense. tfAtlastPoint seems to be unused and distBetweenPoints doesn't do what you expect because you're calculating the distance between a world position and a relative value (0..1).

The question is how do you want your collectibles to be placed? Equal F distance? Equal world unit distance?

Here's a pseudocode:

Code:
for (int i=0;i<31;i++)
{
    var myNewGameObject=new GameObject(...);
    myNewGameObject.position=SplineGroup.Interpolate(i/30); // <= this will be equal F
    myNewgameObject.position=SplineGroup.Interpolate(SplineGroup.DistanceToTF((SplineGroup.Length/30)*i)); <= this will be equal distance
}
Reply
#3
(06-06-2014, 06:33 PM)'Jake' Wrote: Hi,

maybe you didn't post the whole code involved, but what I see makes no sense. tfAtlastPoint seems to be unused and distBetweenPoints doesn't do what you expect because you're calculating the distance between a world position and a relative value (0..1).

The question is how do you want your collectibles to be placed? Equal F distance? Equal world unit distance?

Here's a pseudocode:


Code:
for (int i=0;i<31;i++)
{
var myNewGameObject=new GameObject(...);
myNewGameObject.position=SplineGroup.Interpolate(i/30); // <= this will be equal F
myNewgameObject.position=SplineGroup.Interpolate(SplineGroup.DistanceToTF((SplineGroup.Length/30)*i)); <= this will be equal distance
}
I think it was a bit late at night when I posted that... was also editing the code to remove excess stuff that wasn't related to this question. Smile

The final result I'm looking for is that the first collectable is placed a short distance from the start of the spline, then the next is placed between X and Y random distance after the first, then the next is placed another X and Y random distance from the first, and so on. That's the question (or comment) I should have asked last night. Smile


 
Reply
#4
When using the API, just make sure you don't mix units. Most Curvy API methods accept a relative value TF (0..1 over the whole spline). if you want to work with world unit distances, convert using DistanceToTF() and TFToDistance(). So finding a point on a spline isn't more complicated as finding a point on a straight line.
Reply
#5
i think's it's what's i need somone can confirm
~~<= this will be equal F
is tf ? here
~~override Vector3  Interpolate (float tf)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 13 03-04-2024, 11:06 AM
Last Post: _Aka_
Question Volume Spots inter group distance Sacryn 1 3 02-27-2024, 04:08 PM
Last Post: _Aka_
  Avoiding runtime GC allocations on control point position change Ell223 8 18 02-24-2024, 10:43 AM
Last Post: _Aka_

Forum Jump: