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