Пример #1
0
    private float Heuristic(Node inNode, Node inGoalNode)
    {
        if (inNode.GetType() == typeof(DeathNode))
        {
            return(9999);
        }
        //return (float)Math.Pow((inNode.transform.position - WorldGrid.GetClosestGoalNode(inNode).transform.position).magnitude, 2.0f);
        // return Vector3.Distance(inNode.transform.position, inGoalNode.transform.position);
        return((inNode.transform.position - WorldGrid.GetClosestGoalNode(inNode).transform.position).magnitude + r.Next(Wiggliness));
//        return (inNode.transform.position - inGoalNode.transform.position).magnitude + r.Next(6); // + r.Next(6) to add wigglyness)
    }
Пример #2
0
    public void Start()
    {
        float randomAngle = (float)(r.NextDouble() * 360);

        randomOffset = new Vector3(Mathf.Sin(randomAngle) / 4.0f, 0.18f, Mathf.Cos(randomAngle) / 4.0f);
        //  randomOffset = new Vector3((float)((r.NextDouble() * 0.5f) - 0.25f), (float)((r.NextDouble() * 0.5f) - 0.25f));
        Node startNode = WorldGrid.GetClosestNodeFromPosition(transform.position, true);

        pathToGoal = FindPathToGoalNode(startNode, WorldGrid.GetClosestGoalNode(startNode));
        nodeIndex  = 0;
        lerp       = Vector3.Lerp(Vector3.zero, pathToGoal[nodeIndex].transform.position + randomOffset - transform.position,
                                  0.05f);
    }