void Update() { // --------------------- Example for using this package ---------------------------- Vector3 moveVec = steer.MoveVector(); // In this case we look at the Movement Vector so we can evaluate how close to 0 it is and ocasionally remove some jitter, this evaluation is not always needed. if (moveVec.sqrMagnitude > ConfidenceThreshold) { control.SimpleMove(steer.MoveDirection() * Speed); // This line gets the movement vector from the Context steering controller. } else { control.SimpleMove(Vector3.zero); } // ------------------------------------------------------------------------------------- // This just handles rotating the gameObject Vector3 newRotation; if (LookTarget != null) { newRotation = Quaternion.LookRotation(MapOperations.VectorToTarget(gameObject, LookTarget).normalized).eulerAngles; } else if (!moveVec.Equals(Vector3.zero)) { newRotation = Quaternion.LookRotation(steer.MoveDirection()).eulerAngles; } else { newRotation = Quaternion.LookRotation(transform.forward).eulerAngles; } transform.rotation = Quaternion.Euler(0, newRotation.y, 0); }
private IEnumerator StuckCheck() { for (; ;) { yield return(new WaitForSeconds(1)); if (MapOperations.VectorToTarget(transform.position, lastPosition).magnitude < recomputePathThreshold) { //Debug.Log("Recomputing Path"); RecomputePath(); } lastPosition = transform.position; } }
private Vector3 currentCorner() { if (!hasPath) // Either no path is stored, or no path can be computed { return(transform.position); } float sqrMag = MapOperations.VectorToTarget(transform.position, path.corners[pathIndex]).sqrMagnitude; if (sqrMag < SqrWaypointRadius && pathIndex < path.corners.Length - 1) { pathIndex++; return(path.corners[pathIndex]); } // otherwise there are no more corners or we have not yet reached the next corner return(path.corners[pathIndex]); }
private void scaledMap() { foreach (Vector3 target in targets) { Vector3 targetVector = MapOperations.VectorToTarget(my_position, target); float distance = targetVector.magnitude; if (distance < range) { Vector3 mapVector = InitialVector(); for (int i = 0; i < Weights.Length; i++) { Weights[i] += Vector3.Dot(mapVector, targetVector.normalized) * Mathf.Abs((invertScale * 1f) - (distance / range)) * weight; mapVector = MapOperations.RotateAroundAxis(axis, angle) * mapVector; } } } }
private static bool GetNestedRemoves(MapOperations maps) { bool hasNestedRemoves = false; if (maps != null) { foreach (var mapOperation in maps) { hasNestedRemoves = mapOperation.Value.HasRemoves || GetNestedRemoves(mapOperation.Value.Maps); if (hasNestedRemoves) { break; } } } return(hasNestedRemoves); }
private void standardMap() { sqrRange = range * range; foreach (Vector3 target in targets) { Vector3 targetVector = MapOperations.VectorToTarget(my_position, target); float distance = targetVector.sqrMagnitude; if (distance < sqrRange) { Vector3 mapVector = InitialVector(); for (int i = 0; i < Weights.Length; i++) { Weights[i] += Vector3.Dot(mapVector, targetVector.normalized) * weight; mapVector = MapOperations.RotateAroundAxis(axis, angle) * mapVector; } } } }
public void Execute() { for (int i = 0; i < Weights.Length; i++) { Weights[i] = 0f; } if (!scaled) { standardMap(); } else { scaledMap(); } if (direction == SteerDirection.REPULSE) { Weights = MapOperations.ReverseMap(Weights); } }
public Vector3 GetDirection(float[] contextMap) { float resolutionAngle = steeringParams.ResolutionAngle; float maxValue = 0f; int maxIndex = 0; for (int i = 0; i < contextMap.Length; i++) { if (contextMap[i] > maxValue) { maxValue = contextMap[i]; maxIndex = i; } } Vector3 direction = Vector3.forward * maxValue; if (maxValue == 0f) { return(lastVector); // Keep last direction if no better direction is found } Vector3 nextVector = MapOperations.RotateAroundAxis(steeringParams.ContextMapRotationAxis, resolutionAngle * maxIndex) * direction; float dot = Mathf.Clamp(Vector3.Dot(lastVector.normalized, nextVector.normalized), -1f, 1f); // next direction is within direction change if (dot > MinDot) { lastVector = nextVector; return(lastVector); } float desiredAngleRad = Mathf.Acos(MinDot); lastVector = Vector3.RotateTowards(lastVector, nextVector, desiredAngleRad, 1); return(lastVector); }
public Vector3 GetDirection(float[] contextMap) { float resolutionAngle = steeringParams.ResolutionAngle; float maxValue = 0f; int maxIndex = 0; for (int i = 0; i < contextMap.Length; i++) { if (contextMap[i] > maxValue) { maxValue = contextMap[i]; maxIndex = i; } } Vector3 direction = Vector3.forward * maxValue; if (maxValue == 0f) { if (allowVectorZero) { return(Vector3.zero); } return(lastVector); // return last direction if no better direction is found } if (steeringParams == null) { throw new UnassignedReferenceException("The direction selection algorithm does not know what axis to use, check constructor (PlanarSteeringParameters)."); } // Update cache & return new direction. lastVector = MapOperations.RotateAroundAxis(steeringParams.ContextMapRotationAxis, resolutionAngle * maxIndex) * direction; return(lastVector); }
public void ConvertAddressToUrl() { var ops = new MapOperations(); var contact = new ContactInfo { StreetAddress = "5781 St. Joseph Ave", City = "Stevensville", State = "MI", Zip = null }; // Check that it works without a zip code string result = ops.ConvertAddressToUrl(contact); string expected = "https://www.google.com/maps/embed/v1/place?q=5781+St.+Joseph+Ave,+Stevensville,+MI&zoom=15&key=AIzaSyCqBmnjONAkuxwGlva581PNNi-Q2rLUYaU"; Assert.AreEqual(expected, result); // Check that it works with a zip code contact.Zip = "49127"; result = ops.ConvertAddressToUrl(contact); expected = "https://www.google.com/maps/embed/v1/place?q=5781+St.+Joseph+Ave,+Stevensville,+MI+49127&zoom=15&key=AIzaSyCqBmnjONAkuxwGlva581PNNi-Q2rLUYaU"; Assert.AreEqual(expected, result); }
protected Quaternion rotateAroundAxis(float resolutionAngle) { return(MapOperations.RotateAroundAxis(steeringParameters.ContextMapRotationAxis, resolutionAngle)); }