コード例 #1
0
    protected override void OnCharacterActionStart(Character actor)
    {
        transform = actor.transform;

        HexTile startTile = actor.currentTile;

        if (startTile == null)
        {
            Done();
            return;
        }

        List <HexTile> path = Pathfinder.FindPath(startTile, targetTile, PathFindingMode.None);

        if (path == null)
        {
            Done();
            return;
        }

        Vector3[] line       = NeverdawnUtility.PathAlongTiles(path, 0.1f, 10);
        float     pathLength = NeverdawnUtility.GetPathLength(line);


        GameController.instance.party.PullCharacter(characterToPlace, targetTile.position);

        action = new CharacterMoveAlongPathAction(line, 1000.0f, 1.0f, false);
        action.ActionStart(characterToPlace);
    }
コード例 #2
0
    protected override void OnCharacterActionStart(Character actor)
    {
        transform = actor.transform;

        NavMeshAnimator walker = actor.GetComponentInChildren <NavMeshAnimator>();

        if (walker != null)
        {
            moveSpeed = walker.moveSpeed;
            turnSpeed = walker.turnSpeed;
        }
        else
        {
            moveSpeed = 5.0f;
            turnSpeed = 540.0f;
        }

        if (!run)
        {
            moveSpeed /= 2.0f;
        }

        float distance = Mathf.Min(NeverdawnUtility.GetPathLength(corners), maxDistance);

        distance = 0.0f;
    }
コード例 #3
0
    protected override void OnCharacterActionStart(Character actor)
    {
        transform = actor.transform;

        HexTile startTile = HexTerrain.GetClosestTile(character.position);

        if (startTile == null)
        {
            Done();
            return;
        }

        List <HexTile> path = Pathfinder.FindPath(startTile, targetTile, ignoreTarget ? PathFindingMode.ExcludeTarget : PathFindingMode.None);

        if (path == null)
        {
            Done();
            return;
        }

        if (actor.remainingSteps == 0)
        {
            Done();
            return;
        }

        if (!includeLast)
        {
            path.Remove(targetTile);
        }


        while (path.Count > actor.remainingSteps + 1)
        {
            path.RemoveAt(path.Count - 1);
        }

        targetTile            = path[path.Count - 1];
        actor.remainingSteps -= path.Count - 1;

        Vector3[] line       = NeverdawnUtility.PathAlongTiles(path, 0.1f, 10);
        float     pathLength = NeverdawnUtility.GetPathLength(line);

        action = new CharacterMoveAlongPathAction(line, 1000.0f, 1.0f, run);
        action.ActionStart(actor);
    }
コード例 #4
0
    private List <Vector3> sampleSurroundings(int count, float radius)
    {
        List <Vector3> result = new List <Vector3>();

        float stepWidth = (radius * 2.0f) / (float)count;
        int   count2    = count / 2;

        for (int i = -count2; i < count2; i++)
        {
            for (int j = -count2; j < count2; j++)
            {
                Vector3 position = character.position;
                position.x += stepWidth * i;
                position.z += stepWidth * j;

                NavMeshHit hit;

                if (NavMesh.SamplePosition(position, out hit, 1.0f, NavMesh.AllAreas))
                {
                    position = hit.position;

                    if (Vector3.Distance(position, character.position) <= character.remainingSteps)
                    {
                        NavMeshPath path = new NavMeshPath();

                        if (NavMesh.CalculatePath(character.position, position, NavMesh.AllAreas, path))
                        {
                            if (NeverdawnUtility.GetPathLength(path) <= character.remainingSteps)
                            {
                                result.Add(position);
                            }
                        }
                    }
                }
            }
        }

        return(result);
    }
コード例 #5
0
    protected override void OnCharacterActionStart(Character actor)
    {
        transform = actor.transform;

        NavMeshPath path = new NavMeshPath();

        if (NavMesh.CalculatePath(transform.position, target, NavMesh.AllAreas, path))
        {
            Vector3[] line       = NeverdawnUtility.RelaxPath(NeverdawnUtility.RefinePath(path.corners, 0.1f), 10);
            float     pathLength = NeverdawnUtility.GetPathLength(line);

            if (pathLength - stoppingDistance < walkDistance)
            {
                walkDistance = pathLength - stoppingDistance;
            }

            action = new CharacterMoveAlongPathAction(line, walkDistance, 1.0f, run);
            action.ActionStart(actor);
        }
        else
        {
            Done();
        }
    }
コード例 #6
0
ファイル: WalkCursor.cs プロジェクト: holycrab13/neverdawn
    private void createPath()
    {
        if (NavMesh.CalculatePath(root, targetTransform.position, NavMesh.AllAreas, navMeshPath))
        {
            if (navMeshPath.status != NavMeshPathStatus.PathInvalid)
            {
                float pathLength = NeverdawnUtility.GetPathLength(navMeshPath);

                path = NeverdawnUtility.RelaxPath(NeverdawnUtility.RefinePath(navMeshPath.corners, 0.2f), 10);

                for (int i = 0; i < path.Length; i++)
                {
                    RaycastHit rayHit;

                    // experimental: stick to ground
                    if (Physics.Raycast(path[i] + 2 * Vector3.up, Vector3.down, out rayHit, 4f, 1 << 9))
                    {
                        path[i] = rayHit.point + 0.05f * Vector3.up;
                    }
                }

                if (path.Length > 1)
                {
                    List <Vector3> vertices     = new List <Vector3>();
                    List <int>     triangles    = new List <int>();
                    List <Color>   vertexColors = new List <Color>();

                    Vector3 dir = (path[1] - path[0]);
                    dir.y = 0.0f;
                    dir.Normalize();

                    Vector3 side = Vector3.Cross(dir, Vector3.up).normalized;

                    targetDirection = dir;

                    int colorIndex = 0;

                    vertices.Add(path[0] + width * side);
                    vertices.Add(path[0] - width * side);
                    vertexColors.Add(colors[colorIndex]);
                    vertexColors.Add(colors[colorIndex]);

                    int index = 0;

                    for (int i = 1; i < path.Length - 1; i++)
                    {
                        dir  = ((path[i] - path[i - 1]).normalized + (path[i + 1] - path[i]).normalized) / 2.0f;
                        side = Vector3.Cross(dir, Vector3.up).normalized;

                        float distance = NeverdawnUtility.GetPathLength(path, i);

                        colorIndex = distance > maxDistance ? 1 : 0;
                        // colorIndex = NeverdawnUtility.RepeatIndex((int)(distance / walkAbility.maxDistance), colors.Length);

                        vertices.Add(path[i] + width * side);
                        vertices.Add(path[i] - width * side);

                        vertexColors.Add(colors[colorIndex]);
                        vertexColors.Add(colors[colorIndex]);

                        triangles.Add(index + 0);
                        triangles.Add(index + 2);
                        triangles.Add(index + 3);

                        triangles.Add(index + 1);
                        triangles.Add(index + 0);
                        triangles.Add(index + 3);

                        index += 2;

                        //if(distance < walkAbility.maxDistance && NeverdawnUtility.GetPathLength(line, i + 1) > walkAbility.maxDistance)
                        //{
                        //    Vector3 maxPos = Vector3.zero;

                        //    NeverdawnUtility.SamplePath(line, walkAbility.maxDistance, out maxPos);


                        //}
                    }

                    dir  = path[path.Length - 1] - path[path.Length - 2];
                    side = Vector3.Cross(dir, Vector3.up).normalized;

                    vertices.Add(path[path.Length - 1] + width * side);
                    vertices.Add(path[path.Length - 1] - width * side);

                    vertexColors.Add(colors[colorIndex]);
                    vertexColors.Add(colors[colorIndex]);

                    triangles.Add(index + 0);
                    triangles.Add(index + 2);
                    triangles.Add(index + 3);

                    triangles.Add(index + 1);
                    triangles.Add(index + 0);
                    triangles.Add(index + 3);

                    vertices.Add(path[path.Length - 1] + 1.5f * width * side);
                    vertices.Add(path[path.Length - 1] - 1.5f * width * side);
                    vertices.Add(path[path.Length - 1] + 0.3f * dir.normalized);

                    vertexColors.Add(colors[colorIndex]);
                    vertexColors.Add(colors[colorIndex]);
                    vertexColors.Add(colors[colorIndex]);

                    triangles.Add(vertices.Count - 1);
                    triangles.Add(vertices.Count - 2);
                    triangles.Add(vertices.Count - 3);



                    Mesh mesh = new Mesh();
                    mesh.vertices  = vertices.ToArray();
                    mesh.triangles = triangles.ToArray();
                    mesh.colors    = vertexColors.ToArray();

                    meshFilter.sharedMesh = mesh;
                }
            }
        }
    }