public SplineReticulatedPosition ProcessCrossingRequest(SplineReticulatedPosition cur, SplineReticulatedPosition desired) { //determine if in range float curDist = pos.DistanceBetween(cur); float desDist = pos.DistanceBetween(desired); if ((curDist * desDist) > 0) { //they are on the same side of us, so we aren't in the way of them return(desired); } //determine direction of travel //does that match our mandate //clamp the ret pos with a little bit of wiggle room SplineReticulatedPosition retval = new SplineReticulatedPosition(); retval.CopyVals(desired); if (curDist < 0 && (mode == SplineGateMode.NoGreater || mode == SplineGateMode.NoCrossing)) { retval.CopyVals(pos); retval.distanceFromRetStart *= 0.999f; retval.distanceFromRetStart -= float.Epsilon; } else if (curDist > 0 && (mode == SplineGateMode.NoLess || mode == SplineGateMode.NoCrossing)) { retval.CopyVals(pos); retval.distanceFromRetStart *= 1.001f; retval.distanceFromRetStart += float.Epsilon; } return(retval); }
public override void Update() { if (snappedTarget != null) { //same spline if (trav.spline == snappedTarget.spline) { SplineReticulatedPosition cur = trav.GetReticulatedPosition(); SplineReticulatedPosition clamped = snappedTarget.GetClamped(cur); float dif = cur.DistanceBetween(clamped); if (Mathf.Abs(dif) > closeEnoughTolerance) { float moveBy = Mathf.Sign(dif) * Mathf.Min(Mathf.Abs(dif), maxSpeed * Time.deltaTime); // print (dif); transform.position = trav.Move(moveBy); } } else { //its a new spline just set up there trav.SetReticulatedPosition(snappedTarget.closeRes.retPos); } } }
public void SetReticulatedPosition(SplineReticulatedPosition pos) { spline = pos.spline; curRetProgression = pos.distanceFromRetStart; curSplineSegment = pos.splineNodeIndex; curRetSegment = pos.retSeg; }
public void CopyVals(SplineReticulatedPosition rhs) { spline = rhs.spline; splineNodeIndex = rhs.splineNodeIndex; retSeg = rhs.retSeg; distanceFromRetStart = rhs.distanceFromRetStart; }
void Start() { SplineAnchor an = GetComponent <SplineAnchor>(); if (an != null) { pos = an.retPRes.retPos; } }
public SplineReticulatedPosition GetReticulatedPosition() { SplineReticulatedPosition retval = new SplineReticulatedPosition(); retval.spline = spline; retval.distanceFromRetStart = curRetProgression; retval.splineNodeIndex = curSplineSegment; retval.retSeg = curRetSegment; return(retval); }
public SplineReticulatedPosition GetClamped(SplineReticulatedPosition cur) { SplineReticulatedPosition retval = closeRes != null ? closeRes.retPos : null; foreach (SplineGate sg in splineGates) { if (sg.enabled && sg.gameObject.activeSelf && sg.gameObject.activeInHierarchy) { retval = sg.ProcessCrossingRequest(cur, retval); } } return(retval); }
public override void Update() { if (targetPos != null) { SplineReticulatedPosition cur = trav.GetReticulatedPosition(); float dif = cur.DistanceBetween(targetPos); if (Mathf.Abs(dif) > closeEnoughTolerance) { float moveBy = Mathf.Sign(dif) * Mathf.Min(Mathf.Abs(dif), maxSpeed * Time.deltaTime); //print (dif); transform.position = trav.Move(moveBy); } } }
public float DistanceBetween(SplineReticulatedPosition other) { //choose closest if (other == null || this.spline != other.spline) { return(float.MaxValue); } float sign = 1f; SplineReticulatedPosition near = null, far = null; if (this.splineNodeIndex < other.splineNodeIndex) { near = this; far = other; } else if (this.splineNodeIndex > other.splineNodeIndex) { far = this; near = other; sign = -1; } else if (this.retSeg < other.retSeg) { near = this; far = other; } else if (this.retSeg > other.retSeg) { far = this; near = other; sign = -1; } else//same node and ret seg { //if start seg and end seg the same return dif in distance traveled return(other.distanceFromRetStart - this.distanceFromRetStart); } //add rem distance in this seg float distAccum = near.spline.GetNode(near.splineNodeIndex).GetReticulatedSegment(near.retSeg).length - near.distanceFromRetStart; //add the distance the final seg as already traveled distAccum += far.distanceFromRetStart; int curIndex = near.splineNodeIndex, curSeg = near.retSeg + 1; //run until we are on the same node and same seg while (curIndex < far.splineNodeIndex || curSeg < far.retSeg) { ReticulatedSplineSegment ret = near.spline.GetNode(curIndex).GetReticulatedSegment(curSeg); if (ret != null) { distAccum += ret.length; //move from its seg forward curSeg++; } else { //end of ret info move forward curIndex++; curSeg = 0; } } return(distAccum * sign); }