Inheritance: MonoBehaviour
Example #1
0
    // Update is called once per frame
    private void addPoint(Vector3 pos)
    {
        FollowPath path = (this.target as FollowPath);

        //Undo.RecordObject(path, "New node");
        Undo.RegisterFullObjectHierarchyUndo(path, "New node");

        GameObject point = new GameObject("point");

        point.transform.parent = path.transform;
        NodePath nodePath = point.AddComponent <NodePath>();

        point.transform.position = pos;

        Vector3 lastPos = default(Vector3);

        if (path.points.Count > 0)
        {
            lastPos = path.points [path.points.Count - 1].position;
        }

        Vector3    targetDir = lastPos - point.transform.position;
        Quaternion rot       = Quaternion.LookRotation(targetDir);

        Vector3 point1 = RotateAroundPoint(point.transform.position + new Vector3(0, 0, 3), point.transform.position, rot);
        Vector3 point2 = RotateAroundPoint(point.transform.position + new Vector3(0, 0, -3), point.transform.position, rot);

        nodePath.handler1 = RotateAroundPoint(point1, point.transform.position, Quaternion.Euler(0, 0, 70)) - path.transform.position;
        nodePath.handler2 = RotateAroundPoint(point2, point.transform.position, Quaternion.Euler(0, 0, 70)) - path.transform.position;

        path.points.Add(point.transform);
        Undo.RegisterCreatedObjectUndo(point, "New node");
    }
Example #2
0
    public void init()
    {
        if (initComplete == false)
        {
            //set ref
            gridScript           = Ref.getGridScript();
            visibleObstManager   = GetComponent <VisibleObstManager>();
            managerScript        = Ref.getManagerGO().GetComponent <Manager>();
            recalculateTime      = GetComponent <AgentProps>().cooperationLenght;
            spatialAStarScript   = GetComponent <SpatialAStar>();
            spaceTimeAStarScript = GetComponent <SpaceTimeAStar>();
            agent            = transform;
            followPathScript = agent.GetComponent <FollowPath>();

            //saves initial grid in grid var
            saveInitalGrid();

            spaceTimeAStarScript.init();
            spatialAStarScript.init(grid);
            spaceTimeAStarScript.setSpacialAStarScript(spatialAStarScript);
            managerScript.increaseFrameCount();

            //here we switch the role of target and agent
            spatialAStarScript.FindPathSpatial(target.position, agent.position, true, null);

            path = spaceTimeAStarScript.FindPath(agent.position, target.position, true);

            followPathScript.init();
            followPathScript.setNewPath(path);
        }
        initComplete = true;
    }
Example #3
0
    void Start()
    {
        myRotateType           = new LookWhereGoing();
        myRotateType.character = this;
        myRotateType.target    = myTarget;

        Graph graph = new Graph();

        if (isCheap)
        {
            graph.Build(true);
        }
        else
        {
            graph.Build(false);
        }

        List <Connection> path = Dijkstra.pathFind(graph, start, goal);

        myPath = new GameObject[path.Count + 1];

        int i = 0;

        foreach (Connection co in path)
        {
            myPath[i] = co.getFromNode().gameObject;
            i++;
        }
        myPath[i] = goal.gameObject;

        myMoveType           = new FollowPath();
        myMoveType.character = this;
        myMoveType.path      = myPath;
    }
Example #4
0
    private void AddHandlePoint()
    {
        FollowPath path = (this.target as FollowPath);

        Vector2 pos = editorUtils.GetMousePos(Event.current.mousePosition, path.transform.position.z) - new Vector2(path.transform.position.x, path.transform.position.y);

        Handles.color = new Color(1, 1, 1, 1);

        Vector3 handlePos = new Vector3(pos.x, pos.y, 0) + path.transform.position + offset;

        if (path.points.Count > 0)
        {
            editorUtils.DrawArrow(path.points[path.points.Count - 1].position, handlePos);

            if (path.loop)
            {
                editorUtils.DrawArrow(handlePos, path.points[0].position);
            }
        }

        //GUIStyle     iconStyle = new GUIStyle();
        Handles.color = new Color(1, 1, 1, 0);
        if (editorUtils.IsVisible(handlePos))
        {
            if (Handles.Button(handlePos, SceneView.lastActiveSceneView.camera.transform.rotation, editorUtils.HandleScale(handlePos), editorUtils.HandleScale(handlePos), Handles.CircleHandleCap))
            {
                addPoint(handlePos);
                Selection.activeGameObject = path.gameObject;
            }
        }
    }
Example #5
0
    // Start is called before the first frame update
    void Start()
    {
        kineticsAgent = agent.kineticsAgent;
        steeringAgent = agent.steeringAgent;

        follow = new FollowPath(kineticsAgent, maxSeekAccel, pathOffset);
    }
    // Start is called before the first frame update
    void Start()
    {
        myRotateType           = new LookWhereGoing();
        myRotateType.character = this;
        myRotateType.target    = myTarget;

        Graph myGraph = new Graph();

        myGraph.Build();
        List <Connection> path = Dijkstra.pathfind(myGraph, start, goal);

        // path is a list of connections - convert this to gameobjects for the FollowPath steering behavior
        myPath = new GameObject[path.Count + 1];
        int i = 0;

        foreach (Connection c in path)
        {
            Debug.Log("from " + c.getFromNode() + " to " + c.getToNode() + " @" + c.getCost());
            myPath[i] = c.getFromNode().gameObject;
            i++;
        }
        myPath[i] = goal.gameObject;

        myMoveType           = new FollowPath();
        myMoveType.character = this;
        myMoveType.path      = myPath;
    }
Example #7
0
        private Composite StateBehaviorPS_PathRetreating()
        {
            return(new PrioritySelector(
                       // If no Egress path, build it...
                       new Decorator(context => Path_Egress == null,
                                     new Action(context =>
            {
                Path_Egress = FollowPath.FindPath_Egress(Mob_ToAvoid);
                QBCLog.Info("Retreating back to safespot due to {0}.",
                            Me.Combat
                            ? "combat"
                            : string.Format("{0} too close (dist: {1:F1})", Mob_ToAvoid.SafeName, Mob_ToAvoid.Distance));
            })),

                       // If we've come to the end of our egress path, move back to safe spot...
                       new Decorator(context => !Path_Egress.Any(),
                                     new Action(context =>
            {
                Path_Ingress = null;
                Path_Egress = null;
                State_MainBehavior = StateType_MainBehavior.MovingToSafespot;
            })),

                       // If we've arrived at the current waypoint, dequeue it...
                       new Decorator(context => Navigator.AtLocation(Path_Egress.Peek().Location),
                                     new Action(context => { Path_Egress.Dequeue(); })),

                       new ActionRunCoroutine(
                           context => UtilityCoroutine.MoveTo(
                               Path_Egress.Peek().Location,
                               "retreat",
                               MovementBy))
                       ));
        }
Example #8
0
    public void init()
    {
        //set ref
        GameObject agent     = Ref.getActiveAgent();
        GameObject managerGO = Ref.getManagerGO();
        GameObject plane     = Ref.getPlane();

        managerScript    = managerGO.GetComponent <Manager>();
        findPathScript   = agent.GetComponent <FindPath>();
        followPathScript = agent.GetComponent <FollowPath>();
        agentPropsScript = agent.GetComponent <AgentProps>();

        visObstManagerScript = agent.GetComponent <VisibleObstManager>();

        nodeDiameter = nodeRadius * 2;

        if (levelTxt != null)
        {
            lines = levelTxt.text.Split('\n');
            string firstLine = lines[0];
            gridWorldSize.x = int.Parse(firstLine.Split(' ')[0]);
            gridWorldSize.y = int.Parse(firstLine.Split(' ')[1]);
        }
        GridSizeX = Mathf.RoundToInt(gridWorldSize.x / nodeDiameter);
        GridSizeY = Mathf.RoundToInt(gridWorldSize.y / nodeDiameter);
        GridSizeZ = agentPropsScript.cooperationLenght * 2 + 1;

        plane.transform.localScale = new Vector3(GridSizeX / 10f, 1, GridSizeY / 10f);
        worldBottomLeft            = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2;

        CreateGrid();
    }
    // Use this for initialization
    void Start()
    {
        path.calcDistances();

        steeringBasics = GetComponent <SteeringBasics>();
        followPath     = GetComponent <FollowPath>();
    }
Example #10
0
    // Use this for initialization
    void Start()
    {
        paths.Clear();
        eships.Clear();
        av8ships.Clear();
        foreach (Path p in gameObject.GetComponentsInChildren(typeof(Path)))
        {
            paths.Add(p);
        }
        //Creates the enemy to get shot by
        GameObject leader = GameObject.Instantiate <GameObject> (enemyprefab);

        leader.transform.parent   = this.transform;
        leader.transform.position = this.transform.GetChild(1).position;          //position at the start of the epath
        leader.transform.rotation = this.transform.GetChild(1).rotation;
        FollowPath fpath = leader.AddComponent <FollowPath> ();

        fpath.path    = paths [1];      //follows the epath
        fpath.enabled = fpath.enabled;
        eships.Add(leader);

        //Creates the enemy that will shoot the av8 plane
        leader = GameObject.Instantiate <GameObject> (enemyprefab);
        leader.transform.parent   = this.transform;
        leader.transform.position = this.transform.GetChild(0).TransformPoint(new Vector3(0, 0, -10));            //position at the start of the apath with offset
        leader.transform.rotation = this.transform.GetChild(0).rotation;
        eships.Add(leader);

        //Creates the av8 plane that will shoot the enemy
        leader = GameObject.Instantiate <GameObject> (av8prefab);
        leader.transform.parent   = this.transform;
        leader.transform.position = this.transform.position;
        leader.transform.rotation = this.transform.rotation;
        //Add boid and seek to the  bombs(missiles)
        int count = leader.transform.Find("Bombs").gameObject.transform.childCount;

        for (int i = 0; i < count; i++)
        {
            Boid b = leader.transform.Find("Bombs").GetChild(i).gameObject.AddComponent <Boid> ();
            b.maxSpeed        = 45f;
            b.explosionPrefab = expPrefab;
            Pursue sb = leader.transform.Find("Bombs").GetChild(i).gameObject.AddComponent <Pursue> ();
            sb.target  = eships [0].GetComponent <Boid> ();
            sb.enabled = !sb.enabled;
        }
        av8ships.Add(leader);

        //Creates the av8 plane that will get shot by
        leader = GameObject.Instantiate <GameObject> (av8prefab);
        leader.transform.parent   = this.transform;
        leader.transform.position = this.transform.GetChild(0).position;          //position at the start of the apath
        leader.transform.rotation = this.transform.GetChild(0).rotation;
        fpath         = leader.AddComponent <FollowPath> ();
        fpath.path    = paths [0];      //follows the apath
        fpath.enabled = !fpath.enabled;
        av8ships.Add(leader);

        StartCoroutine(Enemykill());
    }
Example #11
0
    private void Start()
    {
        path.calcDistances();

        steeringBasics2 = GetComponent <SteeringBasics2>();
        wallAvoidance2  = GetComponent <WallAvoidance2>();
        followPath      = GetComponent <FollowPath>();
    }
Example #12
0
    void Start()
    {
        FollowPath pathFinder = GetComponent <FollowPath> ();

        pathFinder.OnDestinationReached += OnDestinationReached;

        properties = GetComponent <EnemyProperties> ();
    }
        public static MessageArrived Send(FollowPath followPath)
        {
            var msg = pool.New();

            msg.Init(followPath);
            MessageManager.GetInstance().Send(msg);
            return(msg);
        }
    // Use this for initialization
    void Start()
    {
        path.calcDistances();

        steeringBasics = GetComponent<SteeringBasics>();
        wallAvoidance = GetComponent<WallAvoidance>();
        followPath = GetComponent<FollowPath>();
    }
Example #15
0
 public void Initialize(FireEnemy givenParent)
 {
     Debug.Log(givenParent);
     this.target    = givenParent.Target;
     this.parent    = givenParent;
     this.damage    = givenParent.Damage;
     this.maxHp     = target.Health[target.Type];
     this.currentHp = target.CurrentHealth;
 }
Example #16
0
    public void SpawnEnemy()
    {
        if (spawn_points.Count > 0)
        {
            Vector3          spawn_pos = spawn_points[Random.Range(0, spawn_points.Count)].transform.position;
            PathManager.Path path      = path_manager.GetCloserPath(spawn_pos);

            if (path != null)
            {
                int enemy_no = Random.Range(1, 4);

                GameObject enemy_go = null;

                switch (enemy_no)
                {
                case 1:
                    enemy_go = yellow_enemy;
                    break;

                case 2:
                    enemy_go = pink_enemy;
                    break;

                case 3:
                    enemy_go = orange_enemy;
                    break;
                }

                if (enemy_go != null)
                {
                    GameObject curr_en = Instantiate(enemy_go, spawn_pos, Quaternion.identity);

                    if (world_parent != null)
                    {
                        curr_en.transform.parent = world_parent.transform;
                    }

                    curr_en.transform.localRotation = Quaternion.Euler(0, 0, 0);
                    enemies.Add(curr_en);

                    FollowPath path_script = curr_en.GetComponent <FollowPath>();

                    if (path_script != null)
                    {
                        path_script.SetPath(path.GetPathList());
                    }

                    Stats stats = curr_en.GetComponent <Stats>();

                    if (stats != null)
                    {
                        stats.SetManagers(this, event_system);
                    }
                }
            }
        }
    }
    static void CreateFollowPath()
    {
        GameObject obj  = new GameObject("New Follow Path");
        FollowPath path = obj.AddComponent <FollowPath>();

        obj.transform.position = editorUtils.GetSpawnPos();
        Selection.activeObject = obj;
        EditorGUIUtility.PingObject(obj);
    }
Example #18
0
 public Patrol(AgentUnit agent, Vector3[] path, float rangeRadius, Action <bool> callback) : base(agent, callback)
 {
     Debug.Assert(followRangeExtra >= 1f);
     this.rangeRadius = rangeRadius;
     targetEnemy      = null;
     attack           = null;
     followPath       = new FollowPath(agent, path, FollowT.LOOP, (_) => {});
     SetCenter(agent.position);
 }
Example #19
0
        // ----------------- Tick method -----------------
        /// <summary> Make a tick with robot brain.</summary>
        public void updateRobot()
        {
            if (currentStrategy != null)
            {
                currentStrategy.calculateNextMove(position, speed, heading, neighbors, out referenceSpeed, out referenceHeading);
            }
            else
            {
                setStrategy(new StandStill());
            }

            // Run collision avoidance code to check if robot is blocked.
            blocked = false;
            blocked = isBlocked();

            if (blocked)
            {
                //setMotorSignals(new int[2] { 0, 0 }); //uncomment if using m3pi robots

                //$$$$$Changes/Additions for RC car$$$$$//
                setMotorSignals(new int[2] {
                    Program.neutralSpeed, motorSignals[1]
                });
                if (neighbors[0].getID() != 0) //The updateRobot() function is called separately for each robot; therefore a new obstacle avoidance strategy needs to be set only for glyph 0.
                {
                    if (!blocktime)            //The first time obstacle is detected, calculate the final point until which obstacle avoidance strategy needs to be valid.
                    {
                        finalPositionX = 2 * neighbors[0].getPosition().X - position.X;
                        finalPositionY = 2 * neighbors[0].getPosition().Y - position.Y;
                        blocktime      = true;
                    }
                    int         nrPointsObsAvoid = 15;
                    DoublePoint positionObst     = neighbors[0].getPosition();

                    if (Math.Abs(finalPositionX - position.X) > 300 || Math.Abs(finalPositionY - position.Y) > 300)
                    {
                        setStrategy(new FollowPath("Avoid Obstacle", FollowPath.createEllipsePoints(200, 100, positionObst, nrPointsObsAvoid)));   //obstacle avoidance path.
                    }
                    else
                    {
                        currentStrategy = Program.strategyList.ElementAt(Program.activeStrategyId);     //After completing half-circle, the robot should continue on it's previous path as set in GUI.
                    }
                }
                else
                {
                    setStrategy(new StandStill());    //For the obstacle, keep the strategy as StandStill.
                }
                //$$$$$$$$$$//
            }
            //else  //uncomment if using m3pi robots
            //{ //uncomment if using m3pi robots
            //  setMotorSignals(controller(speed, heading, referenceSpeed, referenceHeading));    //uncomment if using m3pi robots
            setMotorSignals(controller(speed, heading, referenceHeading));

            //} //uncomment if using m3pi robots
        }
Example #20
0
 // Use this for initialization
 void Start()
 {
     map           = GameObject.Find("Map").GetComponent <TileMap> ().map;
     steeringUtils = GetComponent <SteeringUtils> ();
     followPath    = GetComponent <FollowPath> ();
     rb            = GetComponent <Rigidbody2D> ();
     player        = GameObject.Find("Player").transform;
     laser         = GetComponentInChildren <EnemyLaser> ();
     sr            = GetComponent <SpriteRenderer> ();
 }
    private void Start()
    {
        //Get the waypoints and send them to the car
        List <Node> nodes = GetAllWaypoints();

        //Send the nodes to the car
        FollowPath carPathScript = carTrans.GetComponent <FollowPath>();

        carPathScript.SetPath(nodes, isCircular: true);
    }
    // Use this for initialization
    void Start()
    {
        path.calcDistances();

        steeringBasics = GetComponent<SteeringBasics>();
        followPath = GetComponent<FollowPath>();
        colAvoid = GetComponent<CollisionAvoidance>();

        colAvoidSensor = transform.Find("ColAvoidSensor").GetComponent<NearSensor>();
    }
        public override void OnRecovery()
        {
            base.OnRecovery();
            this.Deactive();
            this.followPath.Release();
            followPath = null;

            fsmMachine.Release();
            this.fsmMachine = null;
        }
Example #24
0
    // Start is called before the first frame update
    void Start()
    {
        myMoveType           = new FollowPath(targets);
        myMoveType.character = this;
        myMoveType.target    = myTarget;

        myRotateType           = new LookWhereGoing();
        myRotateType.character = this;
        myRotateType.target    = myTarget;
    }
        public override void Generate(FollowPath path, float radius)
        {
            base.Generate(path, radius);

            team = Team.Enemies;
            var trigger = gameObject.AddComponent <CircleCollider2D>();

            trigger.isTrigger = true;
            trigger.radius    = radius;
        }
    // Use this for initialization
    void Start()
    {
        path.calcDistances();

        steeringBasics = GetComponent <SteeringBasics>();
        followPath     = GetComponent <FollowPath>();
        colAvoid       = GetComponent <CollisionAvoidance>();

        colAvoidSensor = transform.Find("ColAvoidSensor").GetComponent <NearSensor>();
    }
        void GetCarComponents()
        {
            _carComp            = GetComponent <Car>();
            _distanceSensorComp = GetComponent <DistanceSensor>();
            _followPathComp     = GetComponent <FollowPath>();
            _brakesComp         = GetComponent <Brakes>();
            _gasComp            = GetComponent <Gas>();
            _patienceComp       = GetComponent <Patience>();

            carData = _carComp.carData;
        }
Example #28
0
    // Use this for initialization
    public virtual void Start()
    {
        steeringUtils = GetComponent <SteeringUtils> ();
        followPath    = GetComponent <FollowPath> ();
        rb            = GetComponent <Rigidbody>();

        int[] mapPos = Map.map.worldToMapPoint(transform.position);
        reservePosition(mapPos);

        myDebugCircle = Instantiate(debugCircle, transform.position, Quaternion.identity) as Transform;
    }
    // Start is called before the first frame update
    void Start()
    {
        m_Rotate           = new LookWhereYoureGoing();
        m_Rotate.character = this;
        m_Rotate.target    = target;

        m_Move              = new FollowPath();
        m_Move.character    = this;
        m_Move.path         = m_Path;
        m_Move.targetRadius = targetRadius;
    }
    public void Init(float slowPercentage, float duration)
    {
        this.slowPercentage = slowPercentage;
        this.duration       = duration;

        this.followPath        = GetComponent <FollowPath>();
        this.originalSpeed     = this.followPath.Speed;
        this.followPath.Speed *= this.slowPercentage;

        StartCoroutine(SlowCountdown());
    }
Example #31
0
    void restartPath()
    {
        saveInitalGrid();
        spatialAStarScript.init(grid);
        managerScript.increaseFrameCount();
        //here we switch the role of target and agent
        spatialAStarScript.FindPathSpatial(target.position, agent.position, true, null);

        path             = spaceTimeAStarScript.FindPath(agent.position, target.position, true);
        followPathScript = agent.GetComponent <FollowPath>();
        followPathScript.setNewPath(path);
    }
        public override void OnRecovery()
        {
            base.OnRecovery();
            this.Deactive();
            this.followPath.Release();
            followPath = null;

            fsmMachine.Release();
            this.fsmMachine = null;

            shuttleVisitorList.Clear();
        }
Example #33
0
    // Use this for initialization
    public virtual void Start()
    {
        steeringUtils = GetComponent<SteeringUtils> ();
        followPath = GetComponent<FollowPath> ();
        rb = GetComponent<Rigidbody>();

        int[] mapPos = Map.map.worldToMapPoint(transform.position);
        reservePosition(mapPos);

        myDebugCircle = Instantiate(debugCircle, transform.position, Quaternion.identity) as Transform;
    }
Example #34
0
 public static Vector3 FollowPath(this Mobile vehicle, FollowPath path, float waypointSeekDist)
 {
     if (vehicle == null || path == null || path.IsEmpty) {
         return Vector3.zero;
     }
     if ((path.CurrentWaypoint - vehicle.Position).sqrMagnitude < waypointSeekDist * waypointSeekDist) {
         path.SetNextWaypoint();
     }
     var steering_force = Vector3.zero;
     if (!path.Finished) {
         steering_force = Seek(vehicle, path.CurrentWaypoint);
     } else {
         steering_force = Arrive(vehicle, path.CurrentWaypoint);
     }
     DebugExtension.DebugArrow(vehicle.Position, steering_force, Color.green);
     DebugExtension.DebugWireSphere(vehicle.Position, Color.red, waypointSeekDist);
     return steering_force;
 }
Example #35
0
 void Start()
 {
     spriteRenderer = GetComponent<SpriteRenderer> ();
     followPath = GetComponent<FollowPath>();
     player = GameObject.FindGameObjectWithTag("Player");
     if(isBoss){
     HealthBar = GameObject.FindGameObjectWithTag("HealthOverlay").GetComponent<Image>();
         //if(HealthBar != null){
         //Mask mask =  HealthBar.transform.parent.gameObject.AddComponent<Mask>();
         //mask.MaskEnabled();
         //}
     }
 }
Example #36
0
	void Awake()
	{
		followPath = GetComponent<FollowPath>();
		followPath.enabled = false;
		Debug.Log (followPath);
	}