예제 #1
0
        IEnumerator pathPlayer(PlayerCore player)
        {
            player.SetIsInteracting(false);
            PathData.Node current = GetNode(0);

            while (current != null)
            {
                Vector2 delta = current.position - (Vector2)player.transform.position - player.GetComponent <Rigidbody2D>().velocity *Time.fixedDeltaTime;
                player.MoveCraft(delta.normalized);
                if (delta.sqrMagnitude < PathAI.minDist)
                {
                    if (current.children.Count > 0)
                    {
                        int next = Random.Range(0, current.children.Count);
                        current = GetNode(current.children[next]);
                    }
                    else
                    {
                        current = null;
                    }
                }

                yield return(null);
            }

            player.SetIsInteracting(true);

            if (!asynchronous)
            {
                continueTraversing();
            }
        }
예제 #2
0
    public void SetOwner(IOwner owner)
    {
        this.owner = owner;
        ai.owner   = owner;
        owner.GetUnitsCommanding().Add(this);
        if (owner as AirCarrier || owner as GroundCarrier)
        {
            // GET THE DRONES TO MOVE
            ai.setMode(AirCraftAI.AIMode.Path);
            var path = ScriptableObject.CreateInstance <Path>();
            path.waypoints = new List <Path.Node>();
            var vec = Vector2.zero;
            if (owner as AirCarrier)
            {
                foreach (var ent in BattleZoneManager.getTargets())
                {
                    if (ent && ent is ICarrier && !FactionManager.IsAllied(ent.faction, owner.GetFaction()) && ent.transform)
                    {
                        vec = ent.transform.position;
                    }
                }
            }
            // otherwise this is a ground carrier, drones are defensive for them so set a path to the drone position currently
            else
            {
                var angle = Random.Range(0F, 360);
                vec = owner.GetTransform().position + new Vector3(5 * Mathf.Sin(angle), 5 * Mathf.Cos(angle));
            }

            // TODO: jank, fix this eventually
            var node = new Path.Node();
            node.position = vec;
            node.ID       = 0;
            node.children = new List <int>();
            if (vec != Vector2.zero)
            {
                path.waypoints.Add(node);
            }
            if (owner as AirCarrier)
            {
                ai.setPath(path);
            }
            else
            {
                NodeEditorFramework.Standard.PathData data = new NodeEditorFramework.Standard.PathData();
                data.waypoints = new List <NodeEditorFramework.Standard.PathData.Node>();
                // TODO: LOL THESE TWO ARE DIFFERENT, unify them
                foreach (var point in path.waypoints)
                {
                    var node2 = new NodeEditorFramework.Standard.PathData.Node();
                    node2.ID       = point.ID;
                    node2.children = point.children;
                    node2.position = point.position;
                    data.waypoints.Add(node2);
                }

                ai.setPath(data, null, true);
            }
        }
    }