private void CreateLocationInDirection(Vector2 direction) { Vector2 center = enemyMarker.GetLocation().To2D(); Vector2 secondaryLocation; float heightAtSecondaryLocation; Vector2 previousSecondaryLocation = center; float heightAtPreviousSecondaryLocation = EnvironmentPhysics.FindHeightAt( previousSecondaryLocation.x, previousSecondaryLocation.y ); direction = direction.normalized; Vector2 dx = direction * STEPLENGTH; int numberOfSteps = (int)(radius / STEPLENGTH); for (int i = 0; i < numberOfSteps; i++) { secondaryLocation = center + (dx * i); heightAtSecondaryLocation = EnvironmentPhysics.FindHeightAt( secondaryLocation.x, secondaryLocation.y ); if (Mathf.Abs( heightAtSecondaryLocation - heightAtPreviousSecondaryLocation ) > ACCEPTABLEHEIGHTDIFFERENCEBETWEENSTEPS || !EnvironmentPhysics.WalkableAt(secondaryLocation.x, secondaryLocation.y, ConversionHub.GetSoldierRadius())) { break; } heightAtPreviousSecondaryLocation = heightAtSecondaryLocation; previousSecondaryLocation = secondaryLocation; } Vector3 secondaryLocation3 = new Vector3( previousSecondaryLocation.x, heightAtPreviousSecondaryLocation, previousSecondaryLocation.y ); secondaryLocations.Enqueue(secondaryLocation3); }
private void MoveWithTerrain(float angle) { angle = angle * Mathf.Deg2Rad; Vector3 currentPosition = centerBottom.position; float newX = (Mathf.Cos(angle) * calculateSpeed()) + currentPosition.x; float newZ = (Mathf.Sin(angle) * calculateSpeed()) + currentPosition.z; float newY = EnvironmentPhysics.FindHeightAt(newX, newZ); Vector3 newPosition = new Vector3(newX, newY, newZ); direction.Face(newPosition); if (EnvironmentPhysics.WalkableAt(newPosition.x, newPosition.z, 1)) { float twoDDistance = FastMath.Hyp(currentPosition.x , currentPosition.z , newPosition.x , newPosition.z); Vector3 hypotenuse = newPosition - currentPosition; Vector3 unitHypotenuse = hypotenuse.normalized; unitHypotenuse.Scale(FastMath.CreateVectorCube(twoDDistance)); Vector3 finalPosition = unitHypotenuse + currentPosition; centerBottom.position = new Vector3(finalPosition.x , EnvironmentPhysics.FindWalkableHeightAt(finalPosition.x , finalPosition.z) , finalPosition.z ); } /* * centerBottom is implied to be the child of * the gameobject movementcontroller is attached to */ Transform centerBottomParent = centerBottom.parent; centerBottom.parent = null; body.position = centerBottom.position + displacementFromCenterBottom; centerBottom.parent = centerBottomParent; }