예제 #1
0
 private void CheckPath(Vector3 point)
 {
     //builds patrol path and wanders
     if (!isPointsCollected)
     {
         return;
     }
     if (!agent.pathPending && !agent.hasPath)//clear prime goal so it trys to calculate path again
     {
         agent.primeGoal = Vector2.zero;
     }
     if (point != oldTargetPos || agent.activePath.Count == 0)
     {
         agent.SetDestination(point);
         oldTargetPos = point;
     }
     else if (State == PrimaryEnums.AiState.Wander && agent.remainingDistance < 1)
     {
         currentPatrolPoint++;
         if (currentPatrolPoint == PatrolPoints.Count)
         {
             currentPatrolPoint = 0;
         }
     }
 }
예제 #2
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        ap    = animator.gameObject.GetComponent <AgentPatrol> ();
        agent = animator.gameObject.GetComponent <PolyNavAgent> ();
        shoot = animator.gameObject.GetComponent <RepeatShoot> ();

        oldMaxSpeed     = agent.maxSpeed;
        oldStoppingDist = agent.stoppingDistance;
        oldSlowingDist  = agent.slowingDistance;
        oldAccelRate    = agent.accelerationRate;
        oldDecelRate    = agent.decelerationRate;

        // SetNewAgent ();

        agent.SetDestination(ap.playerLastPos);

        if (shoot)
        {
            UpdateTargetPos();
            shoot.StopShoot();
        }
        shooting = false;
//		if(shoot){
//			shoot.StartShoot ();
//			shooting = true;
//		}
    }
예제 #3
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        agent.SetDestination(ap.playerLastPos);
        UpdateTargetPos();

        if (shoot)
        {
            //Debug.Log ("Shooting: " + shooting.ToString ());
            if (shooting && ap.playerTarget == null)
            {
                // lost player target, stop shooting
                shoot.StopShoot();
                SetOldAgent();
                shooting = false;
            }
            else if (!shooting && ap.playerTarget != null)
            {
                // found player target, start shooting
//				Debug.Log (deltaAngle (ap.playerTarget, animator.transform));
                if (deltaAngle(ap.playerTarget, animator.transform) < startShootAngle)
                {
                    shoot.StartShoot();
                    SetNewAgent();
                    shooting = true;
                }
            }
        }

        if (ap.agent.movingDirection.magnitude != 0f)
        {
            ap.facing = ap.agent.movingDirection;
        }
    }
예제 #4
0
 void Update()
 {
     if (following)
     {
         agent.SetDestination(ball.transform.position);
     }
 }
예제 #5
0
    static int SetDestination(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                PolyNavAgent        obj  = (PolyNavAgent)ToLua.CheckObject <PolyNavAgent>(L, 1);
                UnityEngine.Vector2 arg0 = ToLua.ToVector2(L, 2);
                bool o = obj.SetDestination(arg0);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 3)
            {
                PolyNavAgent         obj  = (PolyNavAgent)ToLua.CheckObject <PolyNavAgent>(L, 1);
                UnityEngine.Vector2  arg0 = ToLua.ToVector2(L, 2);
                System.Action <bool> arg1 = (System.Action <bool>)ToLua.CheckDelegate <System.Action <bool> >(L, 3);
                bool o = obj.SetDestination(arg0, arg1);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: PolyNavAgent.SetDestination"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
예제 #6
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }
            agent.repath = true;
            Vector2 clickPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            if (agent.SetDestination(clickPos))
            {
                player.PlayerMove(clickPos);
                Destroy(Instantiate(clickFx, clickPos, Quaternion.identity), 1f);
            }
        }
        if (agent.dir.x > 0)
        {
            player.SetPlayerDir(true);
        }
        else if (agent.dir.x < 0)
        {
            player.SetPlayerDir(false);
        }
    }
 // Use this for initialization
 void Start()
 {
     _agent = GetComponent <PolyNavAgent>();
     _agent.OnDestinationReached += onDestinationReached;
     getWaypoints();
     _agent.SetDestination(_wpStack.Pop().position);
 }
예제 #8
0
        private void Awake()
        {
            map = GetComponent <PolyNav2D>();
            //map.GenerateMap();
            agent.map = map;
            var destination = (Vector2)agent.transform.position + offset;

            agent.SetDestination(destination);
        }
예제 #9
0
 /// <summary>
 /// if HasLostPlayer(), cast -> postCast
 /// </summary>
 protected override void CastSkill()
 {
     //called every frame
     gotPlayer = m_polyNavAgent.SetDestination(ToVec2(playerTransform.position));
     if (HasLostPlayer())
     {
         SetSkillState(SkillState.postCasting);
     }
 }
 void onDestinationReached()
 {
     Debug.Log("Arrived");
     if (_wpStack.Count == 0)
     {
         getWaypoints();
     }
     _agent.SetDestination(_wpStack.Pop().position);
 }
예제 #11
0
        /// <summary>
        /// Move to a target position, without doing any operation.
        /// </summary>
        public bool MoveTo(Vector2 world)
        {
            if (is_working_)
            {
                return(false);
            }

            agent_.SetDestination(world);
            return(true);
        }
예제 #12
0
 protected override bool SetDestination(Vector3 destination)
 {
     if (destination != prevDestination)
     {
         prevDestination    = destination;
         destinationReached = false;
         return(polyNavAgent.SetDestination(destination, OnDestinationReached));
     }
     return(false);
 }
예제 #13
0
    public override void Act(Transform player, GameObject self)
    {
        agent.SetDestination(player.position);

        Vector2 heading = player.position - self.transform.position;

        heading.Normalize();
        float zRot = Mathf.Atan2(heading.y, heading.x) * Mathf.Rad2Deg;

        self.transform.rotation = Quaternion.Lerp(self.transform.rotation, Quaternion.Euler(0f, 0f, zRot), Time.fixedDeltaTime * rotationSpeed);
    }
예제 #14
0
    private IEnumerator WalkAroundPlayer()
    {
        GetNewPositionAroundPlayer();
        if (!agent.map.PointIsValid(randomlyPos))
        {
            GetNewPositionAroundPlayer();
        }
        yield return(new WaitForSeconds(1f));

        agent.SetDestination(randomlyPos);
        anim.SetBool("Walking", true);
    }
    /// <summary>
    /// chooses a set of random coords for transport to deploy enemy AI's on, And activates transports AI logic.
    /// </summary>
    /// <param name="waypoints"></param>
    public void DeployToRandomLocation(List <Transform> waypoints)
    {
        #region consts for readability

        const string _activateAI = "ActivateAI";

        #endregion consts for readability

        // TODO: Make this code better like MephDaddyX's.
        _availableDeployLocations = new List <Transform>(waypoints);
        Transform chosenDeployLocation = _availableDeployLocations[Random.Range(0, _availableDeployLocations.Count)];

        // Remove deploy location from the list in case it isn't valid.
        // TODO: Maybe have a deployment validity checker on the transport so this isn't needed.
        _availableDeployLocations.Remove(chosenDeployLocation);

        // Attempt to deploy to location.
        _myNavAgent.SetDestination(chosenDeployLocation.position);

        CancelInvoke(_activateAI); ///<see cref="ActivateAI"/>
        Invoke(_activateAI, 2f);
    }
예제 #16
0
    protected void Follow(PolyNavAgent agent, float distanceFollow, bool front)
    {
        if (followCrono < 2f)
        {
            agent.Stop();
            anim.SetBool("Walking", false);
            followCrono += Time.deltaTime;
        }
        else
        {
            followCrono = 2f;
            anim.SetBool("Walking", true);

            if (front)
            {
                if (player.GetComponent <Character_Behaviour>().isLookLeft)
                {
                    agent.SetDestination(new Vector2(player.transform.position.x - (distanceFollow * 0.8f), player.transform.position.y));
                }
                else
                {
                    agent.SetDestination(new Vector2(player.transform.position.x + (distanceFollow * 0.8f), player.transform.position.y));
                }
            }
            else
            {
                if (player.GetComponent <Character_Behaviour>().isLookLeft)
                {
                    agent.SetDestination(new Vector2(player.transform.position.x + (distanceFollow * 0.8f), player.transform.position.y));
                }
                else
                {
                    agent.SetDestination(new Vector2(player.transform.position.x - (distanceFollow * 0.8f), player.transform.position.y));
                }
            }
        }
    }
    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (shoot)
        {
            shoot.StopShoot();
        }
        shooting = false;

        if (agent)
        {
            agent.enabled = true;
        }
        agent.SetDestination(animator.transform.position);
        animator.ResetTrigger("reachedDest");
    }
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    //
    //}

    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (agent)
        {
            if (maxSpeedFactor == 0f)
            {
                agent.enabled = true;
            }
            else
            {
                agent.maxSpeed = oldMaxSpeed;
            }
        }
        agent.SetDestination(animator.transform.position);
    }
예제 #19
0
    public override void Act(Transform player, GameObject self)
    {
        if (agent.remainingDistance <= .1f)
        {
            DestPos = SelectPatrolPoint();
            agent.SetDestination(DestPos);
        }

        Vector2 heading = DestPos - self.transform.position;

        heading.Normalize();
        float zRot = Mathf.Atan2(heading.y, heading.x) * Mathf.Rad2Deg;

        self.transform.rotation = Quaternion.Lerp(self.transform.rotation, Quaternion.Euler(0f, 0f, zRot), Time.fixedDeltaTime * rotationSpeed);
    }
예제 #20
0
    private void RandomlyWander()
    {
        if (!polyNavAgent.hasPath)
        {
            Vector2 randomCirclePoint = Random.insideUnitCircle * wanderRadius;
            randomCirclePoint = new Vector3(randomCirclePoint.x + transform.position.x, randomCirclePoint.y + transform.position.y);

            //Debug.Log("random circle point: " + randomCirclePoint);

            //if (polyNav2D.PointIsValid(randomCirclePoint))
            //{
            //Debug.Log("Point is valid");

            polyNavAgent.SetDestination(randomCirclePoint);
            //}
        }
    }
예제 #21
0
 void RunFSM()
 {
     if (CurrentState == States.PatrolState)
     {
         GetComponent <MoveBetween>().enabled = true;
     }
     if (CurrentState == States.AttackState)
     {
         GetComponent <MoveBetween>().enabled = false;
         if (target != null)
         {
             NavAgent.SetDestination(target.transform.position);
         }
         else
         {
             Debug.Log("Error : The target is miss.");
         }
     }
 }
예제 #22
0
    public override void Act(Transform player, GameObject self)
    {
        if (agent.slowingDistance == normalSlowingDistance)
        {
            agent.slowingDistance = 0;
        }

        if (agent.remainingDistance <= .5f)
        {
            var targetPosition = self.transform.TransformPoint(-1, 0, 0);
            agent.SetDestination(targetPosition);
        }

        Vector2 heading = player.position - self.transform.position;

        heading.Normalize();
        float zRot = Mathf.Atan2(heading.y, heading.x) * Mathf.Rad2Deg;

        self.transform.rotation = Quaternion.Lerp(self.transform.rotation, Quaternion.Euler(0f, 0f, zRot), Time.fixedDeltaTime * rotSpeed);
    }
예제 #23
0
        /// Update is called once per frame
        void Update()
        {
            // Remove all player control when we're in dialogue
            if (FindObjectOfType <DialogueRunner>().IsDialogueRunning == true)
            {
                agent.Stop();
                return;
            }

            if (Input.GetMouseButtonDown(1))
            {
                destination = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                agent.SetDestination(destination);
            }

            // Detect if we want to start a conversation
            if (Input.GetMouseButtonDown(0) && eventPanel.activeInHierarchy == false)
            {
                CheckForNearbyNPC();
            }
        }
예제 #24
0
        IEnumerator TryPath()
        {
            //if agent is already has a path or is currently finding one dont do anything
            if (agent.pathPending || agent.hasPath)
            {
                yield return(0);
            }

            //try setting path to next waypoint
            agent.SetDestination(WayPoints[currWaypoint].position);

            //check for a lack of valid path
            if (!agent.pathPending && !agent.hasPath)
            {
                //clear prime goal so it trys to calculate path again
                agent.primeGoal = Vector2.zero;
                //wait a bit then try again
                yield return(StartCoroutine(StaticUtilities.Wait(0.75f)));

                yield return(StartCoroutine(TryPath()));
            }
        }
예제 #25
0
 protected virtual void goToPlayer()
 {
     agent.SetDestination(player.transform.position);
 }
예제 #26
0
 private void SetNewDestination(Transform _newDestination)
 {
     Destination = _newDestination;
     _polyNavAgent.SetDestination(Destination.position);
 }
예제 #27
0
 protected override bool SetDestination(Vector3 target)
 {
     destinationReached = false;
     return(polyNavAgent.SetDestination(target, OnDestinationReached));
 }
예제 #28
0
        public override void Start(Action <bool> done_cb)
        {
            base.Start(done_cb);

            agent_.SetDestination(target_, Done);
        }
예제 #29
0
 // Update is called once per frame
 void Update()
 {
     navAgent.SetDestination(target.position);
 }
예제 #30
0
    public static void pathToPoint(GameObject who, Vector2 point)
    {
        PolyNavAgent agent = who.GetComponentInChildren <PolyNavAgent>();

        agent.SetDestination(point);
    }