IEnumerator Start()
    {
        NavMeshAgent agent = GetComponent <NavMeshAgent>();

        agent.autoTraverseOffMeshLink = false;
        while (true)
        {
            if (agent.isOnOffMeshLink)
            {
                // Debug.Log(gameObject.name + " starting off-mesh travel");
                if (m_Method == OffMeshLinkMoveMethod.NormalSpeed)
                {
                    yield return(StartCoroutine(NormalSpeed(agent)));
                }
                else if (m_Method == OffMeshLinkMoveMethod.Parabola)
                {
                    yield return(StartCoroutine(Parabola(agent, 2.0f, 0.5f)));
                }
                else if (m_Method == OffMeshLinkMoveMethod.Curve)
                {
                    yield return(StartCoroutine(Curve(agent, 0.5f)));
                }

                if (agent.enabled)
                {
                    agent.CompleteOffMeshLink();
                }

                /*else
                 *  agent.Warp(agent.currentOffMeshLinkData.startPos);*/
            }
            yield return(null);
        }
    }
    private IEnumerator ClimbOrDescend()
    {
        // 네비게이션 이동을 중지
        navMeshAgent.isStopped = true;

        // 현재 위치에 있는 OffMeshLink의 시작/종료 위치
        OffMeshLinkData linkData = navMeshAgent.currentOffMeshLinkData;
        Vector3         start = linkData.startPos, end = linkData.endPos;

        // 오르내리는 시간 설정
        float climbTime   = Mathf.Abs(end.y - start.y) / climbSpeed;
        float currentTime = 0.0f;
        float percent     = 0.0f;

        while (percent < 1)
        {
            // 단순히 deltaTime만 더하면 무조건 1초 후에 percent가 1이 되므로
            // climbTime 변수를 연산해서 시간을 조정
            currentTime += Time.deltaTime;
            percent      = currentTime / climbTime;

            // 시간 경과에 따라 오브젝트의 위치 변경
            transform.position = Vector3.Lerp(start, end, percent);

            yield return(null);
        }

        // OffMeshLink를 이용한 이동 완료
        navMeshAgent.CompleteOffMeshLink();

        // OffMeshLink 이동이 완료됐으니 네이게이션 이동을 계속한다
        navMeshAgent.isStopped = false;
    }
Exemple #3
0
    // Use this for initialization
    IEnumerator Start()
    {
        inv           = GameObject.FindGameObjectWithTag("GameController").GetComponent <InventoryDatabase>();
        controll      = GameObject.FindGameObjectWithTag("GameController").GetComponent <Gamecontroller>();
        cam           = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
        agent         = GameObject.FindGameObjectWithTag("Player").GetComponent <NavMeshAgent>();
        playerTextRef = Resources.Load <GameObject>("Prefab/Player_Text");
        playerText    = Instantiate(playerTextRef);
        playerText.transform.SetParent(GameObject.FindGameObjectWithTag("Main Canvas").transform, false);
        //playerText.transform.localPosition = new Vector3(0, 200,0);
        playerText.transform.localScale = Vector3.one;

        //StartCoroutine(InputListener());
        agent.autoTraverseOffMeshLink = false;
        while (true)
        {
            if (agent.isOnOffMeshLink)
            {
                if (method == OffMeshLinkMoveMethod.Parabola)
                {
                    yield return(StartCoroutine(Parabola(agent, jumpHeight, jumpDuration)));
                }
                agent.CompleteOffMeshLink();
            }
            yield return(null);
        }
    }
    IEnumerator Start()
    {
        NavMeshAgent agent = GetComponent <NavMeshAgent>();

        agent.autoTraverseOffMeshLink = false;
        while (true)
        {
            if (agent.isOnOffMeshLink)
            {
                if (m_Method == OffMeshLinkMoveMethod.NormalSpeed)
                {
                    yield return(StartCoroutine(NormalSpeed(agent)));
                }
                else if (m_Method == OffMeshLinkMoveMethod.Parabola)
                {
                    yield return(StartCoroutine(Parabola(agent, 2.0f, 0.5f)));
                }
                else if (m_Method == OffMeshLinkMoveMethod.Curve)
                {
                    yield return(StartCoroutine(Curve(agent, 0.5f)));
                }
                agent.CompleteOffMeshLink();
            }
            yield return(null);
        }
    }
Exemple #5
0
        private void AlertState()
        {
            if (!CanSeePlayer())
            {
                GetComponent <Animator>().SetBool("IsMoving", true);

                GetComponent <NavMeshAgent>().destination = _lastKnownLocation;

                if (Vector3.Distance(transform.position, _lastKnownLocation) < .1f)
                {
                    State = EnemyState.Searching;
                    GetComponent <Animator>().SetBool("IsMoving", false);
                }
            }
            else
            {
                if (Vector3.Distance(transform.position, _player.transform.position) < MinDistance)
                {
                    GetComponent <Animator>().SetBool("IsMoving", false);
                    GetComponent <Animator>().SetBool("IsAttacking", true);
                    _lastKnownLocation = _player.transform.position;
                    GetComponent <NavMeshAgent>().destination = transform.position;
                }
                else
                {
                    if (_navAgent.isOnOffMeshLink)
                    {
                        if (!_traversingLink)
                        {
                            _currLink       = _navAgent.currentOffMeshLinkData;
                            _traversingLink = true;
                        }

                        var tlerp  = .1f;
                        var newPos = Vector3.Lerp(_currLink.startPos, _currLink.endPos, tlerp);
                        newPos.y          += 2f * Mathf.Sin(Mathf.PI * tlerp);
                        transform.position = newPos;

                        if (_currLink.startPos == _currLink.endPos)
                        {
                            transform.position = _currLink.endPos;
                            _traversingLink    = false;
                            _navAgent.CompleteOffMeshLink();
                            _navAgent.Resume();
                        }
                    }
                    else
                    {
                        GetComponent <Animator>().SetBool("IsMoving", true);

                        _lastKnownLocation = _player.transform.position;
                        GetComponent <NavMeshAgent>().destination = _player.transform.position;

                        var targetRotation = Quaternion.LookRotation(_player.transform.position - transform.position);
                        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, TurnSpeed * Time.deltaTime);
                    }
                }
            }
        }
Exemple #6
0
    static int CompleteOffMeshLink(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        NavMeshAgent obj = LuaScriptMgr.GetNetObject <NavMeshAgent>(L, 1);

        obj.CompleteOffMeshLink();
        return(0);
    }
Exemple #7
0
    static int CompleteOffMeshLink(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        NavMeshAgent obj = (NavMeshAgent)LuaScriptMgr.GetUnityObjectSelf(L, 1, "NavMeshAgent");

        obj.CompleteOffMeshLink();
        return(0);
    }
 //This function is called from an Animation Event
 public void CompleteOffMeshLink()
 {
     //We tell the NavMeshAgent component that we've completed the OffMeshLink
     //We also make sure to set the JumpOffMesh parameter to false and to set the Rigid Body component
     //to normal
     agent.CompleteOffMeshLink();
     anim.SetBool("JumpOffMesh", false);
     rb.isKinematic = false;
 }
        void DoCompleteOffMeshLink()
        {
            if (_agent == null)
            {
                return;
            }

            _agent.CompleteOffMeshLink();
        }
Exemple #10
0
    //Used to start StraightAcross routine and to end the offmeshlink movement
    IEnumerator WaterLink()
    {
        m_traversingLink = true;
        //MoveAcrossLink
        yield return(StartCoroutine(StraightAcross()));

        m_agent.CompleteOffMeshLink(); //Must complete manual offmeshlink to 'land' on other side
        m_traversingLink = false;
    }
    IEnumerator Warp()
    {
        _animator.SetBool("Warp", true);
        yield return(new WaitForSeconds(1f));

        _animator.SetBool("Warp", false);
        agent.CompleteOffMeshLink();
        yield return(null);
    }
Exemple #12
0
    private PlayerInput ResolveInput()
    {
        PlayerInput enemyInput = new PlayerInput();

        if (!sensor.SensesPlayer)
        {
            enemyInput.moveInput = Vector2.zero;
            enemyInput.jump      = true;
            enemyInput.attack    = false;
            enemyInput.ability   = false;
        }
        else
        {
            // Moving towards the player
            enemyAgent.SetDestination(sensor.Player.position);

            enemyInput.moveInput = CondenseVector3(enemyAgent.desiredVelocity);

            Debug.Log(enemyAgent.isOnOffMeshLink);

            if (enemyAgent.isOnOffMeshLink && !traversingLink)
            {
                OffMeshLinkData data = enemyAgent.currentOffMeshLinkData;
                enemyInput.moveInput = CondenseVector3(data.endPos - transform.position);

                enemyInput.jump = !IsBelow(data.endPos);

                if (!Controller.isGrounded)
                {
                    traversingLink = true;
                }
            }
            else if (traversingLink)
            {
                OffMeshLinkData data = enemyAgent.currentOffMeshLinkData;
                enemyInput.moveInput = CondenseVector3(data.endPos - transform.position);
                enemyInput.jump      = !IsBelow(data.endPos);

                if (Controller.isGrounded && Vector3.Distance(transform.position, data.endPos) < 2)
                {
                    traversingLink = false;
                    enemyAgent.CompleteOffMeshLink();
                }
            }
            else
            {
                enemyInput.moveInput = CondenseVector3(enemyAgent.desiredVelocity);

                enemyInput.jump = false;
            }

            enemyInput.attack  = false;
            enemyInput.ability = false;
        }

        return(enemyInput);
    }
        private IEnumerator Locomotion_ClimbAnimation()
        {
            agent.Stop();

            state = State.Climb;
            animator.SetInteger("MoveState", (int)state);

            animator.Play("Idle_ToJumpUpHigh");

            Quaternion startRot  = transform.rotation;
            Vector3    startPos  = transform.position;
            float      blendTime = 0.2F;
            float      tblend    = 0F;



            do
            {
                transform.position = Vector3.Lerp(startPos, linkStart_, tblend / blendTime);
                transform.rotation = Quaternion.Slerp(startRot, linkRot_, tblend / blendTime);
                yield return(null);

                tblend += Time.deltaTime;
            } while(tblend < blendTime);
            transform.position = linkStart_;

            //			anim_.CrossFade(linkAnimationName, 0.1, PlayMode.StopAll);
            //			agent.ActivateCurrentOffMeshLink(false);
            do
            {
                transform.rotation  = linkRot_;
                transform.position += new Vector3(animator.deltaPosition.x, animator.deltaPosition.y * 2.1F / 3, animator.deltaPosition.z);

                yield return(null);
            } while(animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 1);

            //			agent.ActivateCurrentOffMeshLink(true);

            state = State.Idle;
            animator.Play("Idle");

            agent.CompleteOffMeshLink();
            agent.Resume();
        }
    // Update is called once per frame
    void Update()
    {
        if (Vector3.Distance(transform.position, wayfindingTarget.position) > 1)
        {
            navMeshAgent.SetDestination(navMeshAgent.destination);
            findDestination(navMeshAgent.destination);
        }

        if (((Mathf.Abs(navMeshAgent.destination.x - navMeshAgent.nextPosition.x) <= 2.05f) && (Mathf.Abs(navMeshAgent.destination.z - navMeshAgent.nextPosition.z) <= 2.05f)) ||
            ((Mathf.Abs(navMeshAgent.destination.x - navMeshAgent.nextPosition.x) <= 8.05f) && (Mathf.Abs(navMeshAgent.destination.z - navMeshAgent.nextPosition.z) <= 8.05f) && (touchEva == true))
            )

        {
            navMeshAgent.ResetPath();
        }

        if (navMeshAgent.isOnOffMeshLink)
        {
            JumpParam = true;
            anim.SetTrigger("Jump");
            anim.SetBool("JumpParam", JumpParam);
            //With this you can acces the start and the endpoint of the current offmeshlink
            OffMeshLinkData data = navMeshAgent.currentOffMeshLinkData;

            //calculate the final point of the link
            Vector3 endPos = data.endPos + Vector3.up * navMeshAgent.baseOffset;

            //Move the agent to the end point
            navMeshAgent.transform.position = Vector3.MoveTowards(navMeshAgent.transform.position, endPos, navMeshAgent.speed * Time.deltaTime);

            //when the agent reach the end point you should tell it, and the agent will "exit" the link and work normally after that
            if (navMeshAgent.transform.position == endPos)
            {
                navMeshAgent.CompleteOffMeshLink();
            }
        }
        if (Input.GetKeyDown(KeyCode.LeftArrow) && speed > 1)
        {
            speed = speed - 1;
        }
        if (Input.GetKeyDown(KeyCode.RightArrow) && speed < 5)
        {
            speed = speed + 1;
        }
        myText.text = "Current Speed: " + speed;

        animatorInfo = anim.GetCurrentAnimatorStateInfo(0);
        if (animatorInfo.IsName("Blend Tree"))
        {
            anim.speed = speed;
        }
        else
        {
            anim.speed = 1;
        }
    }
Exemple #15
0
    void Update()
    {
        if (PhotonNetwork.isMasterClient)
        {
            if (Time.time > traceTime)
            {
                this.GetComponent <Animation> ().CrossFade("riflerun");                //跑
                players = GameObject.FindGameObjectsWithTag("Player");
                if (players == null || target == null)
                {
                    return;
                }

//				print (target);
                float dist = (target.position - tr.position).sqrMagnitude;
                foreach (GameObject _player in players)
                {
                    if ((_player.transform.position - tr.position).sqrMagnitude < dist)
                    {
                        target = _player.transform;
                        break;
                    }
                }

                nvAgent.CompleteOffMeshLink();
                nvAgent.Resume();
                nvAgent.SetDestination(target.position);                 //开始寻路

                //		nvAgent.destination = target.position;
                traceTime = Time.time + 0.4f;
            }
            if (nvAgent.remainingDistance < 10.0f && target != null)
            {
                nvAgent.Stop(true);                                      //停止寻路  
                this.GetComponent <Animation> ().CrossFade("rifleidle"); //站
                pos2.LookAt(target.position);                            //转向寻路点
                kai_qiang();
            }
        }
        else
        {
            tr.position = Vector3.Lerp(tr.position, currPos, Time.deltaTime * 10.0f);            //接收别的怪物移动
            tr.rotation = Quaternion.Lerp(tr.rotation, currRot, Time.deltaTime * 10.0f);         //接收别的怪物移动
            //this.GetComponent<Animation> ().CrossFade ("riflerun");//跑


            if (nvAgent.remainingDistance < 10.0f && target != null)
            {
                nvAgent.Stop(true);                                      //停止寻路  
                this.GetComponent <Animation> ().CrossFade("rifleidle"); //站
                pos2.LookAt(target.position);                            //转向寻路点
                kai_qiang();
            }
        }
    }
 /// <summary>
 /// [EndOffMeshLink]
 /// OffMeshLink処理を終了する
 /// </summary>
 void EndOffMeshLink()
 {
     //フラグ初期化, タイマーストップ
     m_isStartOffMeshLink = false;
     m_timer.Stop();
     //RigidBodyをKinematicに、Velocity = 0
     m_rigidBody.isKinematic = true;
     m_rigidBody.velocity    = Vector3.zero;
     //OffMeshLink終了, Stop解除
     m_navMeshAgent.CompleteOffMeshLink();
     m_navMeshAgent.isStopped = false;
 }
Exemple #17
0
 void Update()
 {
     if (agent.enabled)
     {
         if (agent.isOnOffMeshLink && !isTraversing)
         {
             StartCoroutine(Parabola(agent, 2.0f, 0.7f));
             if(!isTraversing)
                 agent.CompleteOffMeshLink();
         }
     }
 }
    IEnumerator Start()
    {
        NavMeshAgent agent = GetComponent <NavMeshAgent>();

        agent.autoTraverseOffMeshLink = false;
        while (true)
        {
            if (agent.isOnOffMeshLink)
            {
                OffMeshLinkData offMeshLinkData = agent.currentOffMeshLinkData;
                NavMeshLink     link            = (NavMeshLink)agent.navMeshOwner;
                int             AreaType        = link.area;

                if (Vector3.Distance(offMeshLinkData.endPos, agent.destination) < Vector3.Distance(offMeshLinkData.startPos, agent.destination))
                {
                    LinkTraversalConfiguration configuration = NavMeshLinkTraversalTypes.Find((type) => type.AreaType == AreaType);

                    if ((configuration != null && configuration.MoveMethod == OffMeshLinkMoveMethod.NormalSpeed) || (configuration == null && DefaultMoveMethod == OffMeshLinkMoveMethod.NormalSpeed))
                    {
                        OnLinkStart?.Invoke(OffMeshLinkMoveMethod.NormalSpeed);
                        yield return(StartCoroutine(MoveAtNormalSpeed(agent)));

                        OnLinkEnd?.Invoke(OffMeshLinkMoveMethod.NormalSpeed);
                    }
                    else if ((configuration != null && configuration.MoveMethod == OffMeshLinkMoveMethod.Parabola) || (configuration == null && DefaultMoveMethod == OffMeshLinkMoveMethod.Parabola))
                    {
                        OnLinkStart?.Invoke(OffMeshLinkMoveMethod.Parabola);
                        yield return(StartCoroutine(MoveParabola(agent, ParabolaHeight, Vector3.Distance(offMeshLinkData.startPos, offMeshLinkData.endPos) / agent.speed)));

                        OnLinkEnd?.Invoke(OffMeshLinkMoveMethod.Parabola);
                    }
                    else if ((configuration != null && configuration.MoveMethod == OffMeshLinkMoveMethod.Curve) || (configuration == null && DefaultMoveMethod == OffMeshLinkMoveMethod.Curve))
                    {
                        OnLinkStart?.Invoke(OffMeshLinkMoveMethod.Curve);
                        yield return(StartCoroutine(MoveCurve(agent, Vector3.Distance(offMeshLinkData.startPos, offMeshLinkData.endPos) / agent.speed)));

                        OnLinkEnd?.Invoke(OffMeshLinkMoveMethod.Curve);
                    }
                    else if ((configuration != null && configuration.MoveMethod == OffMeshLinkMoveMethod.Teleport) || (configuration == null && DefaultMoveMethod == OffMeshLinkMoveMethod.Teleport))
                    {
                        OnLinkStart?.Invoke(OffMeshLinkMoveMethod.Teleport);
                        OnLinkEnd?.Invoke(OffMeshLinkMoveMethod.Teleport);
                    }
                }

                agent.CompleteOffMeshLink();
            }

            yield return(null);
        }
    }
    /////////////////////*************************************************/////////////////////

    void FixedUpdate()
    {
        if (this.anim.IsPlaying("Stund Up"))
        {
            agent.isStopped = true;
        }
        else
        {
            agent.isStopped = false;;
        }
        if (Vector3.Distance(agent.transform.position, agent.destination) <= stopRadius())
        {
            setMovementState(MOVEMENT_STATE.STOPPED);
            if (this.futureStopState == STOPPED_STATE.PLAYING)
            {
                transform.LookAt(GameObject.Find("Camera").transform.position);
            }
        }
        else
        {
            if (agent.isOnOffMeshLink)
            {
                if (!isUp())
                {
                    if (previousMovState != MOVEMENT_STATE.JUMPINGLOW)
                    {
                        setMovementState(MOVEMENT_STATE.JUMPINGHIGH);
                    }
                }
                else
                {
                    if (previousMovState != MOVEMENT_STATE.JUMPINGHIGH)
                    {
                        setMovementState(MOVEMENT_STATE.JUMPINGLOW);
                    }
                }

                OffMeshLinkData data   = agent.currentOffMeshLinkData;
                Vector3         endPos = data.endPos + Vector3.up * agent.baseOffset;
                agent.transform.position = Vector3.MoveTowards(agent.transform.position, endPos, agent.speed * Time.deltaTime);
                if (agent.transform.position == endPos)
                {
                    agent.CompleteOffMeshLink();
                }
            }
            else
            {
                setMovementState(MOVEMENT_STATE.MOVING);
            }
        }
    }
Exemple #20
0
    public void CompleteOffMeshLink()
    {
        matchTargetEndPos = Vector3.zero;

        if (navMeshAgent.enabled && navMeshAgent.isOnNavMesh)
        {
            navMeshAgent.ActivateCurrentOffMeshLink(true);

            navMeshAgent.CompleteOffMeshLink( );
            navMeshAgent.isStopped = false;

            navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.HighQualityObstacleAvoidance;
        }
    }
        /// <summary>
        /// Updates the velocity and look rotation using the off mesh link.
        /// </summary>
        /// <returns>True if the off mesh link was handled.</returns>
        protected virtual bool UpdateOffMeshLink()
        {
            if (m_NavMeshAgent.currentOffMeshLinkData.linkType == OffMeshLinkType.LinkTypeJumpAcross ||
                (m_NavMeshAgent.currentOffMeshLinkData.linkType == OffMeshLinkType.LinkTypeManual && m_NavMeshAgent.currentOffMeshLinkData.offMeshLink.area == m_ManualOffMeshLinkIndex))
            {
                // Ignore the y difference when determining a look direction and velocity.
                // This will give XZ distances a greater impact when normalized.
                var direction = m_NavMeshAgent.currentOffMeshLinkData.endPos - m_Transform.position;
                direction.y = 0;
                if (direction.sqrMagnitude > 0.1f || m_CharacterLocomotion.Grounded)
                {
                    var nextPositionDirection = m_Transform.InverseTransformPoint(m_NavMeshAgent.currentOffMeshLinkData.endPos);
                    nextPositionDirection.y = 0;
                    nextPositionDirection.Normalize();

                    m_InputVector.x = nextPositionDirection.x;
                    m_InputVector.y = nextPositionDirection.z;
                }

                // Jump if the agent hasn't jumped yet.
                if (m_JumpAbility != null && (m_NavMeshAgent.currentOffMeshLinkData.linkType == OffMeshLinkType.LinkTypeJumpAcross ||
                                              (m_JumpAcrossManualOffMeshLink && m_NavMeshAgent.currentOffMeshLinkData.linkType == OffMeshLinkType.LinkTypeManual &&
                                               m_NavMeshAgent.currentOffMeshLinkData.offMeshLink.area == m_ManualOffMeshLinkIndex)))
                {
                    if (!m_JumpAbility.IsActive && (m_FallAbility == null || !m_FallAbility.IsActive))
                    {
                        m_CharacterLocomotion.TryStartAbility(m_JumpAbility);
                    }
                }
                return(true);
            }
            else if (m_NavMeshAgent.currentOffMeshLinkData.linkType == OffMeshLinkType.LinkTypeDropDown && m_CharacterLocomotion.Grounded)
            {
                m_NavMeshAgent.CompleteOffMeshLink();
            }
            return(false);
        }
Exemple #22
0
    IEnumerator Jump()
    {
        NavMeshAgent agent = GetComponent <NavMeshAgent>();

        agent.autoTraverseOffMeshLink = false;
        while (true)
        {
            if (agent.isOnOffMeshLink)
            {
                StartCoroutine(Parabola(agent, JumpHeight, JumpDuration));
                agent.CompleteOffMeshLink();
            }
            yield return(null);
        }
    }
Exemple #23
0
    IEnumerator Start()
    {
        NavMeshAgent agent = GetComponent <NavMeshAgent>();

        agent.autoTraverseOffMeshLink = false;
        while (true)
        {
            if (agent.isOnOffMeshLink)
            {
                yield return(StartCoroutine(Teleport(agent)));
            }
            agent.CompleteOffMeshLink();
            yield return(null);
        }
    }
    private IEnumerator Start()
    {
        NavMeshAgent agent = GetComponent <NavMeshAgent>();

        agent.autoTraverseOffMeshLink = false;  // set to false to use specific way to traverse off-mesh links
        while (true)
        {
            if (agent.isOnOffMeshLink)  // to check if the agent is positionned on a OffMeshLink
            {
                yield return(StartCoroutine(Parabola(agent, 2f, 0.5f)));

                agent.CompleteOffMeshLink(); // agent will pause at an off-mesh link until this function is called
            }
            yield return(null);
        }
    }
Exemple #25
0
 void Update()
 {
     //寻路完毕
     if (agent.pathStatus == NavMeshPathStatus.PathComplete && agent.remainingDistance <= 0 && !agent.pathPending)
     {
         state = AnimState.IDLE;
         anim.SetBool("move", false);
     }
     else
     {
         if (agent.isOnOffMeshLink)
         {
             agent.CompleteOffMeshLink();
         }
     }
 }
Exemple #26
0
        IEnumerator NormalSpeed(NavMeshAgent agent)
        {
            var data   = agent.currentOffMeshLinkData;
            var endPos = data.endPos + Vector3.up * agent.baseOffset;

            agent.updateRotation = false;
            while (agent.transform.position != endPos)
            {
                agent.transform.rotation = Quaternion.RotateTowards(agent.transform.rotation, Quaternion.LookRotation(endPos - agent.transform.position), agent.angularSpeed * Time.deltaTime);
                agent.transform.position = Vector3.MoveTowards(agent.transform.position, endPos, agent.speed * Time.deltaTime);
                yield return(null);
            }
            agent.updateRotation = true;
            agent.CompleteOffMeshLink();
            _linkRoutine = null;
        }
Exemple #27
0
    private IEnumerator start()
    {
        NavMeshAgent agent = GetComponent <NavMeshAgent>();

        agent.autoTraverseOffMeshLink = false;
        while (true)
        {
            if (agent.isOnOffMeshLink)
            {
                yield return(StartCoroutine(Parabola(agent, 2f, 0.5f)));

                agent.CompleteOffMeshLink();
            }
            yield return(null);
        }
    }
Exemple #28
0
    IEnumerator Jump(float duration)
    {
        OffMeshLinkData data     = _navAgent.currentOffMeshLinkData;
        Vector3         startPos = _navAgent.transform.position;
        Vector3         endPos   = data.endPos + (_navAgent.baseOffset * Vector3.up);
        float           time     = 0.0f;

        while (time <= duration)
        {
            float t = time / duration;
            _navAgent.transform.position = Vector3.Lerp(startPos, endPos, t) + JumpCurve.Evaluate(t) * Vector3.up;
            time += Time.deltaTime;
            yield return(null);
        }
        _navAgent.CompleteOffMeshLink();
    }
Exemple #29
0
    // Update is called once per frame
    void Update()
    {
        HasPath     = _navAgent.hasPath;
        PathPending = _navAgent.pathPending;
        PathStale   = _navAgent.isPathStale;
        PathStatus  = _navAgent.pathStatus;

        if (_navAgent.isOnOffMeshLink)
        {
            if (_navAgent.isOnOffMeshLink)
            {
                StartCoroutine(Jump(1.0f));
                return;
            }
        }

        // if we don't have a path and one isn't pending then set the next
        // waypoint as the target, otherwise if the path is stale regenerate path
        if ((_navAgent.remainingDistance <= _navAgent.stoppingDistance && !PathPending) || PathStatus == NavMeshPathStatus.PathInvalid /*|| PathStatus == NavMeshPathStatus.PathPartial*/)
        {
            SetNextDestination(true);
        }
        else
        if (_navAgent.isPathStale)
        {
            SetNextDestination(false);
        }


        IEnumerator Jump(float duration)
        {
            OffMeshLinkData data     = _navAgent.currentOffMeshLinkData;
            Vector3         startPos = _navAgent.transform.position;
            Vector3         endPos   = data.endPos + (_navAgent.baseOffset * Vector3.up);
            float           time     = 0.0f;

            while (time < duration)
            {
                float t = time / duration;
                _navAgent.transform.position = Vector3.Lerp(startPos, endPos, t) + (JumpCurve.Evaluate(t) * Vector3.up);
                time += Time.deltaTime;
                yield return(null);
            }

            _navAgent.CompleteOffMeshLink();
        }
    }
Exemple #30
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, 100f))
         {
             set = hit.point;
         }
     }
     nav.SetDestination(set);
     if (nav.autoTraverseOffMeshLink)
     {
         nav.CompleteOffMeshLink();
     }
 }