03-02-2018, 05:45 PM
So I have this 'running' experience going, and I basically have path splits. The runner can choose left/right, and then they'll jump to the appropriate spline. I've managed to essentially reverse engineer the code from the train example, but I wonder if this is a bit ridiculous:
The previous node contains metadata that has the text of the new path, Right=Lost Lake, Left=Thick Forest, and also a direct game object reference the first control point of the said paths.
So put this meta data script on the node before the turn:
Then on Control Point End do this:
So, if you'll notice, my code is relying on matching what's in the metadata to what's in the connection point. If you look at my screenshot, it's confusing to me to just say use connection 1 or connection 2, because that seems to randomly change depending on (I think) the order in which I've created my paths. Purple is the path I'm on "Deep Canyon", and the Red is the paths I can choose.
So this works, just fine.. but I feels like it should be easier. Hopefully my code isn't too hard to read, I'm still getting better at C#
The previous node contains metadata that has the text of the new path, Right=Lost Lake, Left=Thick Forest, and also a direct game object reference the first control point of the said paths.
So put this meta data script on the node before the turn:
Code:
public class metaTurnInfo : CurvyMetadataBase, ICurvyMetadata
{
public string leftDiscription;
public CurvySplineSegment left;
public string rightDiscription;
public CurvySplineSegment right;
}
Then on Control Point End do this:
Code:
double connectionDistance;
public void OnCPEnd (CurvySplineMoveEventArgs e)
{
mData = e.ControlPoint.PreviousControlPoint.GetMetadata<metaTurnInfo>();
//THIS IS JUST DEBUG STUFF, TELLS ME THE NAMES OF THE PATH CHOICES
String s = "";
if (mData)
{
for (int i = 0; i < e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint).Count; i++)
{
if (e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[i] == mData.left)
{ s = e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[i].ToString() + " is LEFT"; }
else
{ s = e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[i].ToString(); }
console(s);
}
} else
{
console("No mData");
for (int i = 0; i < e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint).Count; i++)
{
s = e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[i].ToString();
console(s);
}
}
//THIS is part of the UI, but if the user fails to choose a direction when it comes time to change paths, it'll default to the direction the player is looking, 0=left, 1=right
if (turnDirection == -1) turnDirection = lookDirection;
int d = 0;
//MDATA only will exist if there's a choice to make, if not it will just connect to the next path
if (mData)
{
console("mData");
for (int i = 0; i < e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint).Count; i++)
{
if (turnDirection == 0)
if (e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[i] == mData.left) d = i;
if (turnDirection == 1)
if (e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[i] == mData.right) d = i;
console(i + " " + d);
}
} else
{
console("No mData");
for (int i = 0; i < e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint).Count; i++)
{
if (e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[i].FollowUp == null) d = i;
}
}
e.Follow(e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[d]);
SplineController controller = (SplineController)e.Sender;
controller.Spline = e.Spline;
controller.RelativePosition = e.TF;
isTurning = false;
turnDirection = -1;
TurnHUD.SetActive(false);
}
So, if you'll notice, my code is relying on matching what's in the metadata to what's in the connection point. If you look at my screenshot, it's confusing to me to just say use connection 1 or connection 2, because that seems to randomly change depending on (I think) the order in which I've created my paths. Purple is the path I'm on "Deep Canyon", and the Red is the paths I can choose.
So this works, just fine.. but I feels like it should be easier. Hopefully my code isn't too hard to read, I'm still getting better at C#