Ejemplo n.º 1
0
        private void ApplyTerrainMinimum()
        {
            float terrainHeight = EnvironmentPhysics.FindHeightAt(
                camIndependentLocation.position.x,
                camIndependentLocation.position.z
                );
            float heightAboveTerrain = camIndependentLocation.position.y
                                       - terrainHeight;
            float tempVerticalAngle = verticalAngle;

            while (heightAboveTerrain < minimumHeightFromTerrain &&
                   tempVerticalAngle < 89)
            {
                camIndependentLocation.RotateAround(
                    focus.position,
                    new Vector3(camIndependentLocation.right.x,
                                0,
                                camIndependentLocation.right.z
                                ),
                    1
                    );
                tempVerticalAngle++;
                heightAboveTerrain = camIndependentLocation.position.y
                                     - terrainHeight;
            }
        }
Ejemplo n.º 2
0
    public void DrawWithGizmos()
    {
        Gizmos.color = Color.black;
        foreach (Vector3 p in lookPoints)
        {
            Gizmos.DrawCube(new Vector3(p.x, EnvironmentPhysics.FindHeightAt(p.x, p.z) + 1, p.z), Vector3.one);
        }

        //Gizmos.color = Color.white;

        /*foreach (Line l in turnBoundaries) {
         *      l.DrawWithGizmos (10);
         * }*/
    }
Ejemplo n.º 3
0
    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);
    }
Ejemplo n.º 4
0
    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;
    }