Beispiel #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;
         }
     }
 }
Beispiel #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;
//		}
    }
Beispiel #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;
        }
    }
Beispiel #4
0
 void Update()
 {
     if (following)
     {
         agent.SetDestination(ball.transform.position);
     }
 }
Beispiel #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));
        }
    }
Beispiel #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);
 }
Beispiel #8
0
        private void Awake()
        {
            map = GetComponent <PolyNav2D>();
            //map.GenerateMap();
            agent.map = map;
            var destination = (Vector2)agent.transform.position + offset;

            agent.SetDestination(destination);
        }
Beispiel #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);
 }
Beispiel #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);
        }
Beispiel #12
0
 protected override bool SetDestination(Vector3 destination)
 {
     if (destination != prevDestination)
     {
         prevDestination    = destination;
         destinationReached = false;
         return(polyNavAgent.SetDestination(destination, OnDestinationReached));
     }
     return(false);
 }
Beispiel #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);
    }
Beispiel #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);
    }
Beispiel #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);
    }
Beispiel #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);
    }
Beispiel #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);
            //}
        }
    }
Beispiel #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.");
         }
     }
 }
Beispiel #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);
    }
Beispiel #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();
            }
        }
Beispiel #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()));
            }
        }
 protected virtual void goToPlayer()
 {
     agent.SetDestination(player.transform.position);
 }
Beispiel #26
0
 private void SetNewDestination(Transform _newDestination)
 {
     Destination = _newDestination;
     _polyNavAgent.SetDestination(Destination.position);
 }
Beispiel #27
0
 protected override bool SetDestination(Vector3 target)
 {
     destinationReached = false;
     return(polyNavAgent.SetDestination(target, OnDestinationReached));
 }
Beispiel #28
0
        public override void Start(Action <bool> done_cb)
        {
            base.Start(done_cb);

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

        agent.SetDestination(point);
    }