The general idea is, I have a constant forward movement vector, and I want to determine that vector from the forward vector of the closest point on a spline. This spline editor I’m using is the Hermite Spline Controller. That being said, I have little to no idea how to go about determining the closest point along the spline. The method I tried was creating a class to reference the spline (SplineReferencer) and store the closest point along it while the character moves. I would find the closest point along a straight line from one node to the next, and use that to tell me my approximate spline location, this is not working as id like though. What would be the best method to go about doing this? Are there better spline editors that I should try? Advice more than welcome.
So… your character is starting off at the first node of the spline? Or the character can approach the spline from any direction and you want to find the closest node to put him on it?
If its the first one, I’d guess the splines are stored in an array and its a simple matter of incrementing the index to find the next node. Can you give an example scenario of what you’re trying to do, I’m not really following too well.
Neither…The character will be relatively close to the spline at all times, and the splines direction will influence the character’s movement.
Requested example: The character will be endlessly flying through a tunnel, the player is free to move about the tunnel to dodge obstacles or grab collectables, but there will always be a constant forward direction the character moves in. The tunnel can go up, down, curve, and move in really any general direction. The spline is what I’m using for reference to know what my relative forward will be.
So player movement like starfox then.
I THINK you’re asking how to go about keeping track of what the next node in the spline is. I haven’t used the spline editor you’re using but you should just be able to store or access the list of nodes from some array, then just keep going iterating to the next node when you hit one. Another way, without that spline controller, is just to make yourself a bunch of empty gameobjects and rotate them to the forward vectors you want, and place them all into an array… but I realize that might be a little harder unless you set up some gizmos and debug line renderers so you can see the path you’re making.
But if you’re asking how to find the forward vectors of each spline node… not sure, depends on the way the splines are being generated and if you can rotate each node the way you want. If not… I think you can figure out which way the next forward is by subtracting the position of the current node from the position of the next node.
Sorry if this isn’t helping.
Well, basically I just wanted a decent method of determining my closest point on the spline for reference. What I had tried at first was finding the closest two nodes that were in the array sequentially, but that wouldn’t always return the correct nodes for reference. So on top of that I added some half space tests, using normals derived from the two nodes (this one pointing at that one, and that one pointing at this one) This worked better, but was still not right, because this could leave large areas unaccounted for in corners. The solution I ended up going with was using this nodes forward vector, and the next nodes negative forward vector for the half-space tests. So, the two nodes that were closest, and that were validated by the half space test were the ones I want to reference.