Exemplo n.º 1
0
        public override void OnStart()
        {
            this.prevEventKey      = this.Merchant.EventKey;
            this.Merchant.EventKey = EventType.DoorOpen;
            OffMeshLinkData currentOffMeshLinkData = this.Merchant.NavMeshAgent.get_currentOffMeshLinkData();
            DoorPoint       component1             = (DoorPoint)((Component)((OffMeshLinkData) ref currentOffMeshLinkData).get_offMeshLink()).GetComponent <DoorPoint>();

            this.isDoorOpen   = !((OffMeshLinkData) ref currentOffMeshLinkData).get_activated() || Object.op_Equality((Object)component1, (Object)null) || component1.IsOpen;
            this.CurrentPoint = !this.isDoorOpen ? (ActionPoint)component1 : (ActionPoint)null;
            if (this.isDoorOpen)
            {
                this.Merchant.EventKey = this.prevEventKey;
            }
            base.OnStart();
            if (!Object.op_Inequality((Object)this.CurrentPoint, (Object)null))
            {
                return;
            }
            DoorAnimation component2 = (DoorAnimation)((Component)this.CurrentPoint).GetComponent <DoorAnimation>();

            if (!Object.op_Inequality((Object)component2, (Object)null))
            {
                return;
            }
            ActionPointInfo outInfo;

            this.CurrentPoint.TryGetAgentActionPointInfo(EventType.DoorOpen, out outInfo);
            PlayState playState = Singleton <Resources> .Instance.Animation.MerchantCommonActionAnimStateTable[outInfo.eventID][outInfo.poseID];

            component2.Load(playState.MainStateInfo.InStateInfo.StateInfos);
            component2.PlayAnimation(this.animInfo.inEnableBlend, this.animInfo.inBlendSec, this.animInfo.inFadeOutTime, this.animInfo.layer);
        }
Exemplo n.º 2
0
        public override void AlignForOffMeshLinkTraversal(Agent agent)
        {
            OffMeshLinkData data     = navMeshAgents[agent].currentOffMeshLinkData;
            Vector3         startPos = data.startPos + Vector3.up * navMeshAgents[agent].baseOffset;
            Vector3         endPos   = data.endPos + Vector3.up * navMeshAgents[agent].baseOffset;

            // Need to know the type - for now just handle ladders - then doors
            UnityEngine.Object owner  = navMeshAgents[agent].navMeshOwner;
            GameObject         ladder = (owner as Component).gameObject;

            // Is agent going up or down the ladder?
            bool goingUp = endPos.y - startPos.y > 0f;

            if (goingUp)
            {
                agent.transform.position = ladder.transform.GetChild(0).position;
                agent.transform.LookAt(ladder.transform.GetChild(0));
            }
            else
            {
                agent.transform.position = ladder.transform.GetChild(1).position;
                agent.transform.LookAt(ladder.transform.GetChild(1));
                agent.transform.Rotate(new Vector3(0f, 180f, 0f));
            }
        }
    IEnumerator MoveAcrossNavMeshLink()
    {
        //agent.enabled = false;
        OffMeshLinkData data = agent.currentOffMeshLinkData;

        agent.updateRotation = false;

        Vector3 startPos = agent.transform.position;
        Vector3 endPos   = data.endPos + Vector3.up * agent.baseOffset;
        float   duration = (endPos - startPos).magnitude / agent.velocity.magnitude;
        float   t        = 0.0f;
        float   tStep    = 1.0f / duration;

        while (t < 1.0f)
        {
            transform.position = Vector3.Lerp(startPos, endPos, t);
            agent.destination  = transform.position;
            t += tStep * Time.deltaTime;
            yield return(null);
        }
        transform.position   = endPos;
        agent.updateRotation = true;
        agent.CompleteOffMeshLink();
        MoveAcrossNavMeshesStarted = false;
        //agent.enabled = true;
    }
Exemplo n.º 4
0
    IEnumerator Parabola(NavMeshAgent agent, float height, float duration)
    {
        OffMeshLinkData data           = agent.currentOffMeshLinkData;
        Vector3         startPos       = agent.transform.position;
        Vector3         endPos         = data.endPos + Vector3.up * agent.baseOffset;
        float           normalizedTime = 0.0f;

        while (normalizedTime < 1.0f)
        {
            if (startPos.y + 1 < endPos.y)
            {
                float yOffset = (height * 0.9f) * 4.0f * (normalizedTime - normalizedTime * normalizedTime);
                agent.transform.position = Vector3.Lerp(startPos, endPos, normalizedTime) + yOffset * Vector3.up;
                normalizedTime          += Time.deltaTime / (duration + 0.1f);
            }
            else if (startPos.y > endPos.y + 1)
            {
                float yOffset = height * 4.0f * (normalizedTime - normalizedTime * normalizedTime);
                agent.transform.position = Vector3.Lerp(startPos, endPos, normalizedTime) + yOffset * Vector3.up;
                normalizedTime          += Time.deltaTime / duration;
            }
            else
            {
                float yOffset = height * 4.0f * (normalizedTime - normalizedTime * normalizedTime);
                agent.transform.position = Vector3.Lerp(startPos, endPos, normalizedTime) + yOffset * Vector3.up;
                normalizedTime          += Time.deltaTime / duration;
            }



            yield return(null);
        }
    }
Exemplo n.º 5
0
        public void DoJump()
        {
            agent.Stop(true);

            if (!traversingLink)
            {
                animator.CrossFade(jumpState, 0);
                currLink = agent.currentOffMeshLinkData;
                start    = agent.transform.position;
                end      = currLink.endPos;
                NavMeshHit hit;
                NavMesh.SamplePosition(end, out hit, 1, 1);
                end            = hit.position;
                traversingLink = true;
                return;
            }
            agent.transform.LookAt(new Vector3(end.x, agent.transform.position.y, end.z));
            AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);

            if (info.IsName(jumpState) && !animator.IsInTransition(0))
            {
                float tlerp  = info.normalizedTime;
                var   newPos = Vector3.Lerp(start, end, tlerp);
                newPos.y += 0.6f * Mathf.Sin(Mathf.PI * info.normalizedTime);
                agent.transform.position = newPos;
            }

            if (!info.IsName(jumpState) && !animator.IsInTransition(0) || Vector3.Distance(agent.transform.position, end) < 0.3f)
            {
                traversingLink = false;
                agent.CompleteOffMeshLink();
                agent.Resume();
            }
        }
        private string SelectLinkAnimation()
        {
            OffMeshLinkData link  = agent.currentOffMeshLinkData;
            float           distS = (transform.position - link.startPos).magnitude;
            float           distE = (transform.position - link.endPos).magnitude;

            if (distS < distE)
            {
                linkStart_ = link.startPos;
                linkEnd_   = link.endPos;
            }
            else
            {
                linkStart_ = link.endPos;
                linkEnd_   = link.startPos;
            }

            Vector3 alignDir = linkEnd_ - linkStart_;

            alignDir.y = 0;
            linkRot_   = Quaternion.LookRotation(alignDir);

            if (link.linkType == OffMeshLinkType.LinkTypeManual && linkStart_.y < linkEnd_.y)
            {
                return("Locomotion_ClimbAnimation");
            }
            else
            {
                return("Locomotion_JumpAnimation");
            }
        }
Exemplo n.º 7
0
    private IEnumerator ClimbOrDescend()
    {
        // 네비게이션을 이용한 이동을 잠시 중지한다
        navMeshAgent.isStopped = true;

        // 현재 위치에 있는 OffMeshLink의 시작/종료 위치
        OffMeshLinkData linkData = navMeshAgent.currentOffMeshLinkData;
        Vector3         start    = linkData.startPos;
        Vector3         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;
            // 시간 경과(최대 1)에 따라 오브젝트의 위치를 바꿔준다
            transform.position = Vector3.Lerp(start, end, percent);

            yield return(null);
        }

        // OffMeshLink를 이용한 이동 완료
        navMeshAgent.CompleteOffMeshLink();
        // OffMeshLink 이동이 완료되었으니 네비게이션을 이용한 이동을 다시 시작한다
        navMeshAgent.isStopped = false;
    }
Exemplo n.º 8
0
    // Move around nav mesh link just like on road
    IEnumerator MoveAcrossNavMeshLink()
    {
        OffMeshLinkData data = _navMeshAgent.currentOffMeshLinkData;

        _navMeshAgent.updateRotation = false;


        var tmpPos = _navMeshAgent.destination;

        Vector3 startPos = _navMeshAgent.transform.position;
        Vector3 endPos   = data.endPos;

        endPos.y = 0;
        float duration = (endPos - startPos).magnitude / _navMeshAgent.velocity.magnitude;
        float t        = 0.0f;
        float tStep    = 1.0f / duration;

        while (t < 1.0f)
        {
            transform.position = Vector3.Lerp(startPos, endPos, t);
            transform.LookAt(endPos);
            _navMeshAgent.destination = transform.position;
            t += tStep * Time.deltaTime;
            yield return(null);
        }
        transform.position           = endPos;
        _navMeshAgent.destination    = tmpPos;
        _navMeshAgent.updateRotation = true;
        _navMeshAgent.CompleteOffMeshLink();
        _moveAcrossNavMeshesStarted = false;
    }
Exemplo n.º 9
0
    // Moves NavAgent manually straight downwards
    IEnumerator Fall(NavMeshAgent agent, float duration)
    {
        float height = 0.001f;
        //float duration = 0.2f;

        OffMeshLinkData data   = agent.currentOffMeshLinkData;
        Vector3         endPos = data.startPos;

        while (agent.transform.position != endPos)
        {
            agent.transform.position = Vector3.MoveTowards(agent.transform.position, endPos, agent.speed * Time.deltaTime);
            yield return(null);
        }

        data = agent.currentOffMeshLinkData;
        Vector3 startPos = agent.transform.position;

        endPos = data.endPos + Vector3.up * agent.baseOffset;
        float normalizedTime = 0.0f;

        while (normalizedTime < 1.0f)
        {
            float yOffset = height * 4.0f * (normalizedTime - normalizedTime * normalizedTime);
            agent.transform.position = Vector3.Lerp(startPos, endPos, normalizedTime) + yOffset * Vector3.up;
            normalizedTime          += Time.deltaTime / duration;
            yield return(null);
        }
    }
Exemplo n.º 10
0
    //通过脚本控制分离地面的跳跃
    private void AgentOffMeshLink()
    {
        // Debug.Log("isOnOffMeshLink:" + nav.isOnOffMeshLink);
        // nav.currentOffMeshLinkData
        //Debug.Log(nav.currentOffMeshLinkData.activated);
        //Debug.Log(nav.currentOffMeshLinkData.linkType);

        OffMeshLinkData data = nav.currentOffMeshLinkData;

        //如果此时正在往下跳
        if (nav.isOnOffMeshLink && data.linkType == OffMeshLinkType.LinkTypeManual)
        {
            //Link跳跃比例
            linkScale += Time.deltaTime / offMeshLinkInterval;
            //计算抛物线y方向的偏移量
            float upOffset = (linkScale - linkScale * linkScale) * jumpHeight;
            //设置角色的位置
            transform.position = Vector3.up + Vector3.up * upOffset + Vector3.Lerp(data.startPos, data.endPos, linkScale);

            //比例完成超过100%
            if (linkScale > 1)
            {
                //完成分离路面导航
                nav.CompleteOffMeshLink();
                linkScale = 0;
            }
        }
    }
Exemplo n.º 11
0
    void Update()
    {
        if (agent.isOnOffMeshLink)
        {
            if (!traversingLink)
            {
                currLink = agent.currentOffMeshLinkData;

                anim.SetTrigger(jumpHash);
                traversingLink = true;
            }
            else if (!anim.IsInTransition(0))
            {
                if (anim.GetCurrentAnimatorStateInfo(0).tagHash != jumpHash)
                {
                    agent.CompleteOffMeshLink();
                    agent.Resume();
                    agent.nextPosition = currLink.endPos;
                    traversingLink     = false;
                }
            }
        }
        else
        {
            anim.SetFloat("MoveSpeed", agent.velocity.magnitude);
        }
    }
Exemplo n.º 12
0
    public IEnumerator Jump(float duration, float delay)
    {
        OffMeshLinkData data = multiplayerBotStateManager.agent.currentOffMeshLinkData;

        jumpDir    = new Vector3((data.endPos - data.startPos).x, 0f, (data.endPos - data.startPos).z).normalized;
        isGrounded = false;
        multiplayerBotStateManager.agent.enabled = false;

        yield return(new WaitForSeconds(Clamp(delay, 0f, .6f)));

        if (controller.isGrounded)
        {
            velocity.y = actualJumpHeight;
        }

        yield return(new WaitForSeconds(duration));

        while (!controller.isGrounded)
        {
            if (!enabled)
            {
                break;
            }

            isGrounded = true;
            multiplayerBotStateManager.agent.enabled = true;
            yield return(null);
        }
    }
Exemplo n.º 13
0
    /*-----------*/
    // On Update //
//	void Update(){
//
//		//Check that we have nav agent setup first
//		if (agent) {
//
//			/* Traversing off of Mesh Link onto next prefab Tile */
//			if (agent.isOnOffMeshLink) {
//				OffMeshLinkData data = agent.currentOffMeshLinkData;
//
//				//Calculate end point of link
//				Vector3 endPos = data.endPos + Vector3.up * agent.baseOffset;
//
//				//Move the agent to the end point
//				agent.transform.position = Vector3.MoveTowards(agent.transform.position, endPos, agent.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(agent.transform.position == endPos)
//				{
//					agent.CompleteOffMeshLink();
//				}
//			}else{
//
//				//If Infront of the player -- try to evade based on angle from player to us
//				if (transform.position.z >= player.position.z) {
//					Vector3 playerDir = transform.position - player.position;
//					currentAngle = Vector3.Angle (playerDir, Vector3.forward);
//				} else { //If behind the player, run in a straightfoward direction
//					currentAngle = 0;
//				}
//
//				//Inverse the angle of direction dependent on relative x-axis position to player
//				// (or leave un-inversed to have them criss-cross the player)
//
//				/* Normal Evasion */
//				//if (player.position.x > transform.position.x) {
//				//	currentAngle = currentAngle*-1; //evasive
//				//}
//
//				/* Criss-cross evasion */
//				if (player.position.x < transform.position.x) {
//					currentAngle = currentAngle * -1; //criss cross
//				}
//
//				Debug.Log ("current Y Rot: " + currentAngle);
//
//				//Clamps running angle into a forward motion (clamped within -30 +30 degree range)
//				float clampedAngle = Mathf.Clamp (currentAngle, -30, 30); //get clamped foward angle from player
//				//Debug.Log ("clamped Y Rot: " + clampedAngle);
//
//				//Calculate character position on map as a percentage to identify the clamped rotation of the character
//				//to prevent them over steering into a wall / also calculate a random offset to potential correct guttering
//				float mapPositionPerc = Mathf.InverseLerp (-mapWidth, mapWidth, this.transform.position.x);
//				//	Debug.Log ("Map Position = " + mapPositionPerc);
//				float negativeAngleBoundary = (boundaryClamp * mapPositionPerc) * -1;
//				float positiveAngleBoundary = boundaryClamp - Mathf.Abs (negativeAngleBoundary);
//				//	Debug.Log ("Negative angle Clamp = " + negativeAngleBoundary);
//				//	Debug.Log ("Positive Angle Clamp = " + positiveAngleBoundary);
//				float lowerBoundEvasion = evasionRange * mapPositionPerc;
//				float upperBoundEvasion = evasionRange - lowerBoundEvasion;
//				//Debug.Log ("Map Position = " + mapPositionPerc);
//				//Debug.Log("Lower Evasion Bound = " + (-lowerBoundEvasion));
//				//Debug.Log("Upper Evasion Bound = " + upperBoundEvasion);
//
//				//Begin moving to point
//				//float rOffset = 0;
//				float rOffset = Random.Range (-lowerBoundEvasion, upperBoundEvasion);
//				Debug.Log ("Offset = " + rOffset);
//				//Vector3 rotation = new Vector3 (0,  currentAngle + Random.Range(-lowerBoundEvasion, upperBoundEvasion) , 0);
//				this.transform.eulerAngles = new Vector3 (0, Mathf.Clamp (clampedAngle + rOffset, negativeAngleBoundary, positiveAngleBoundary), 0);
//				//Vector3 moveposition = transform.position + (rotation) * 2;
//				Vector3 moveposition = transform.position + transform.forward * 2;
//				Vector3 finalPosition = new Vector3 (Mathf.Clamp (moveposition.x, -mapWidth, mapWidth), moveposition.y, moveposition.z);
//				//Debug.Log ("Clamped final x = " + finalPosition.x);
//				agent.destination = finalPosition;
//
//			}
//		}
//	}


    IEnumerator moveAcrossMeshLink()
    {
        OffMeshLinkData data = agent.currentOffMeshLinkData;

        agent.updateRotation = false;
        //Calculate end point of link
        Vector3 endPos = data.endPos + Vector3.up * agent.baseOffset;

        do
        {
            //Move the agent to the end point
            agent.transform.position = Vector3.MoveTowards(agent.transform.position, endPos, agent.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 (agent.transform.position == endPos)
            {
                Debug.Log("At End Point");
                transform.position   = endPos;
                agent.updateRotation = true;
                agent.CompleteOffMeshLink();
                agent.ResetPath();
                meshWalk = true;
            }
            yield return(null);
        } while (!meshWalk);
    }
    /// <summary>
    /// This coroutine manages the motion of the monster accross door links.
    /// </summary>
    /// <returns>Null</returns>
    IEnumerator MoveAcrossDoorLink()
    {
        // Mark that we have started moving across the link (prevents another copy of this coroutine from being started)
        moveAccrossLinkStarted = true;
        // Get the data from the navmesh about the door link
        OffMeshLinkData data = agent.currentOffMeshLinkData;

        // Calculate the start and ending position of the link
        Vector3 startPos = agent.transform.position;
        Vector3 endPos   = data.endPos;                                                            // + Vector3.up * agent.baseOffset;
        // Using the start and end positions calculate how long it will take (the square magnitudes are used so this is an approximation)
        float duration = (endPos - startPos).sqrMagnitude / doorMovementSpeed / doorMovementSpeed; // Divide by doorMovementSpeed squared

        // Create a variable which tracks how long we have been squeezing through the door (time is scaled between 0 and 1 so that interpolations can work)
        float time = 0.0f;

        while (time < 1.0f)   // Continue squeezing until our calculated time has elapsed.
        // Each time this loop runs we interoplate the monster's position so that it slides a little closer to the end of the link.
        //transform.position = Vector3.Lerp(startPos, endPos, t);
        {
            transform.position = Vector3.Slerp(startPos, endPos, time);

            // Add the elapsed time to the current time (it has to be divided by the total duration so that the final total is 1)
            time += Time.deltaTime / duration;
            // Pause this coroutine and process everything else which needs to be processed
            yield return(null);
        }

        // Make sure that the entity's position is the end of the link (we do use a few approximations)
        transform.position = endPos;
        // Mark that we have finished traversing the link
        agent.CompleteOffMeshLink();
        moveAccrossLinkStarted = false;
    }
Exemplo n.º 15
0
Arquivo: AI.cs Projeto: Horsuna/server
 public void traverse()
 {
     if (this.traversed == 0f)
     {
         this.traversed = Time.realtimeSinceStartup;
     }
     if ((double)(Time.realtimeSinceStartup - this.traversed) >= 0.25)
     {
         this.traversed          = 0f;
         base.transform.position = this.agent.currentOffMeshLinkData.endPos;
         this.agent.CompleteOffMeshLink();
         this.agent.Resume();
     }
     else
     {
         Transform       transforms       = base.transform;
         Vector3         vector3          = this.agent.currentOffMeshLinkData.startPos;
         OffMeshLinkData offMeshLinkDatum = this.agent.currentOffMeshLinkData;
         transforms.position = Vector3.Lerp(vector3, offMeshLinkDatum.endPos, (Time.realtimeSinceStartup - this.traversed) * 4f);
         Transform       transforms1       = base.transform;
         OffMeshLinkData offMeshLinkDatum1 = this.agent.currentOffMeshLinkData;
         float           single            = offMeshLinkDatum1.endPos.z - this.agent.currentOffMeshLinkData.startPos.z;
         float           single1           = this.agent.currentOffMeshLinkData.endPos.x;
         Vector3         vector31          = this.agent.currentOffMeshLinkData.startPos;
         transforms1.rotation = Quaternion.Euler(0f, 90f - 57.29578f * Mathf.Atan2(single, single1 - vector31.x), 0f);
     }
 }
Exemplo n.º 16
0
    IEnumerator Jump(float duration)
    {
        _jumping = true;
        _animator.SetTrigger("Jump");


        OffMeshLinkData data     = _navAgent.currentOffMeshLinkData;
        Vector3         startPos = _navAgent.transform.position;
        Vector3         endPos   = data.endPos + (_navAgent.baseOffset * Vector3.up);

        _navAgent.transform.rotation = Quaternion.LookRotation(data.endPos);

        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();
        _jumping            = false;
        _navAgent.isStopped = true;
        yield return(new WaitForSeconds(1.0f));

        _navAgent.isStopped = false;
    }
Exemplo n.º 17
0
    IEnumerator Jump(float duration)
    {
        OffMeshLinkData data = _navAgent.currentOffMeshLinkData;

        Vector3 startPos = _navAgent.transform.position;

        // L'End position viene recuperata da OffMeshLink data e regolata per l'offset base dell'Agent
        Vector3 endPos = data.endPos + (_navAgent.baseOffset * Vector3.up);

        float time = 0.0f;

        while (time <= duration)
        {
            float t = time / duration;

            // Calcolo un LERP tra la Start Position e la End Position e regolo l'altezza in base alla
            // valutazione del tempo t sulla JumpCurve
            _navAgent.transform.position = Vector3.Lerp(startPos, endPos, t) + (JumpCurve.Evaluate(t) * Vector3.up);

            time += Time.deltaTime;
            yield return(null);
        }

        // Ancora prima di completare il colegamento
        // mi assicuro che l'Agent si esattamente sulla posizione finale
        _navAgent.transform.position = endPos;

        // informa l'Agent che può riprendere il controllo
        _navAgent.CompleteOffMeshLink();
    }
Exemplo n.º 18
0
    /// <summary>
    /// Jump to destination on off mesh link.
    /// </summary>
    /// <param name="duration">The total time in seconds to complete the jump.</param>
    /// <returns></returns>
    IEnumerator Jump(float duration)
    {
        // Get the current OffMeshLink data
        OffMeshLinkData data = this.navAgent.currentOffMeshLinkData;

        // Start Position is agent current position
        Vector3 startPos = this.navAgent.transform.position;

        // End position is fetched from OffMeshLink data and adjusted for baseoffset of agent
        Vector3 endPos = data.endPos + (this.navAgent.baseOffset * Vector3.up);

        // Used to keep track of time
        float time = 0.0f;

        // Keep iterating for the passed duration
        while (time <= duration)
        {
            // Calculate normalized time
            float t = time / duration;

            // Lerp between start position and end position and adjust height based on evaluation of t on Jump Curve
            this.navAgent.transform.position = Vector3.Lerp(startPos, endPos, t) + (JumpCurve.Evaluate(t) * Vector3.up);

            // Accumulate time and yield each frame
            time += Time.deltaTime;
            yield return(null);
        }

        // All done so inform the agent it can resume control
        this.navAgent.CompleteOffMeshLink();
    }
Exemplo n.º 19
0
    private void CheckClimb()
    {
        OffMeshLinkData ladder = agent.currentOffMeshLinkData;

        if (ladder.activated && gameObject.layer == LayerMask.NameToLayer("KingMonster"))
        {
//			GetComponent<Rigidbody> ().useGravity = false;
            if (GameObject.Find("TempHandle").GetComponent <TempController> ().GetTemp() < ICE_TEMP && !iceBreaking)
            {
                GetComponentInChildren <Animator> ().SetBool("attack", true);
                iceBreaking = true;
                iceBroken   = false;
                Invoke("BreakIce", 3f);
            }
            else if (iceBroken)
            {
                transform.eulerAngles = new Vector3(0, 0, 0);
                float upDown = ladder.endPos.y > ladder.startPos.y ? 1f : -1f;
                transform.position = new Vector3(ladder.endPos.x, transform.position.y + 0.1f * upDown, transform.position.z);
                IgnoreGround(true);
                if (Mathf.Abs(transform.position.y - ladder.startPos.y) > Mathf.Abs(ladder.endPos.y - ladder.startPos.y))
                {
                    agent.CompleteOffMeshLink();
                    iceBreaking = false;
                    IgnoreGround(false);
                }
            }
        }
    }
Exemplo n.º 20
0
        protected override bool Reason(AIBehaviors fsm)
        {
            if (navMeshAgent == null)
            {
                if (returnToPreviousState)
                {
                    fsm.ChangeActiveState(fsm.previousState);
                }
                else
                {
                    fsm.ChangeActiveState(transitionState);
                }
                return(false);
            }
            else if (!hasLinkData)
            {
                OffMeshLinkData offMeshLinkData = navMeshAgent.currentOffMeshLinkData;

                startPosition = fsmTransform.position;
                endPosition   = offMeshLinkData.endPos + AddDistanceToEndPosition(offMeshLinkData);

                hasLinkData = true;

                navMeshAgentEnabledState = navMeshAgent.enabled;
                navMeshAgent.enabled     = false;
            }

            return(true);
        }
Exemplo n.º 21
0
        public override void OnStart()
        {
            AgentActor agent = this.Agent;

            agent.EventKey = EventType.DoorOpen;
            OffMeshLinkData currentOffMeshLinkData = agent.NavMeshAgent.get_currentOffMeshLinkData();
            DoorPoint       component1             = (DoorPoint)((Component)((OffMeshLinkData) ref currentOffMeshLinkData).get_offMeshLink()).GetComponent <DoorPoint>();

            agent.TargetInSightActionPoint = (ActionPoint)component1;
            this._actionMotion             = new PoseKeyPair()
            {
                postureID = -1,
                poseID    = -1
            };
            base.OnStart();
            if (!Object.op_Inequality((Object)agent.CurrentPoint, (Object)null))
            {
                return;
            }
            DoorAnimation component2 = (DoorAnimation)((Component)agent.CurrentPoint).GetComponent <DoorAnimation>();

            if (!Object.op_Inequality((Object)component2, (Object)null))
            {
                return;
            }
            ActionPointInfo actionPointInfo = agent.Animation.ActionPointInfo;
            PlayState       playState       = Singleton <Resources> .Instance.Animation.AgentActionAnimTable[actionPointInfo.eventID][actionPointInfo.poseID];

            component2.Load(playState.MainStateInfo.InStateInfo.StateInfos);
            ActorAnimInfo animInfo = agent.Animation.AnimInfo;

            component2.PlayAnimation(animInfo.inEnableBlend, animInfo.inBlendSec, playState.MainStateInfo.FadeOutTime, animInfo.layer);
        }
Exemplo n.º 22
0
        private void DoGetOffMeshLinkData()
        {
            OffMeshLinkData data = agent.currentOffMeshLinkData;

            if (!activated.IsNone)
            {
                activated.Value = data.activated;
            }
            if (!endPos.IsNone)
            {
                endPos.Value = data.endPos;
            }
            if (!linkType.IsNone)
            {
                linkType.Value = data.linkType.ToString();
            }
            if (!startPos.IsNone)
            {
                startPos.Value = data.startPos;
            }
            if (!valid.IsNone)
            {
                valid.Value = data.valid;
            }
        }
        IEnumerator CheckOffMeshLink()
        {
            do
            {
                //Debug.Log(Vector3.Distance(transform.eulerAngles, desiredRotation.eulerAngles));
                method = OffMeshLinkMoveMethod.Grounded;
                yield return(new WaitForEndOfFrame());
            }while (quickTurn);
            //while ((Vector3.Distance(transform.eulerAngles, desiredRotation.eulerAngles) > 0f) && actions);

            yield return(new WaitForEndOfFrame());

            OffMeshLinkData data           = agent.currentOffMeshLinkData;
            OffMeshLinkType linkType       = data.linkType;
            string          offMeshLinkTag = string.Empty;

            if (data.offMeshLink)
            {
                offMeshLinkTag = data.offMeshLink.tag;
            }

            switch (linkType)
            {
            case OffMeshLinkType.LinkTypeDropDown:
                agent.autoTraverseOffMeshLink = false;
                method = OffMeshLinkMoveMethod.DropDown;
                break;

            case OffMeshLinkType.LinkTypeJumpAcross:
                agent.autoTraverseOffMeshLink = false;
                method = OffMeshLinkMoveMethod.JumpAcross;
                break;

            case OffMeshLinkType.LinkTypeManual:
                switch (offMeshLinkTag)
                {
                case "StepUp":
                    agent.autoTraverseOffMeshLink = false;
                    method = OffMeshLinkMoveMethod.Action;
                    break;

                case "JumpOver":
                    agent.autoTraverseOffMeshLink = false;
                    method = OffMeshLinkMoveMethod.Action;
                    break;

                case "ClimbUp":
                    agent.autoTraverseOffMeshLink = false;
                    method = OffMeshLinkMoveMethod.Action;
                    break;

                default:
                    agent.autoTraverseOffMeshLink = false;
                    method = OffMeshLinkMoveMethod.Grounded;
                    break;
                }
                break;
            }
        }
Exemplo n.º 24
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);
                    }
                }
            }
        }
Exemplo n.º 25
0
    static int _CreateOffMeshLinkData(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 0);
        OffMeshLinkData obj = new OffMeshLinkData();

        LuaScriptMgr.PushValue(L, obj);
        return(1);
    }
Exemplo n.º 26
0
    IEnumerator Teleport(NavMeshAgent agent)
    {
        OffMeshLinkData data   = agent.currentOffMeshLinkData;
        Vector3         endpos = data.endPos + Vector3.up * agent.baseOffset;

        agent.transform.position = endpos;
        yield return(null);
    }
Exemplo n.º 27
0
        public override void OnStart()
        {
            this.Merchant.EventKey = EventType.Move;
            OffMeshLinkData currentOffMeshLinkData = this.Merchant.NavMeshAgent.get_currentOffMeshLinkData();

            this.CurrentPoint = (ActionPoint)((Component)((OffMeshLinkData) ref currentOffMeshLinkData).get_offMeshLink()).GetComponent <ActionPoint>();
            base.OnStart();
            this.Merchant.NavMeshObstacle.set_carveOnlyStationary(false);
        }
 public void In(
     [FriendlyName("Agent", "The NavMeshAgent agent.")] NavMeshAgent agent,
     [FriendlyName("Destination", "The Destination to navigate towards.")] out Vector3 destination,
     [FriendlyName("Stopping Distance", "Stop within this distance from the target position.")] out float stoppingDistance,
     [FriendlyName("Velocity", "The current velocity of the NavMeshAgent component.")] out Vector3 velocity,
     [FriendlyName("Next Position", "The next position on the path.")] out Vector3 nextPosition,
     [FriendlyName("Steering Target", "The current steering target - usually the next corner or end point of the current path. (Read Only)")] out Vector3 steeringTarget,
     [FriendlyName("Desired Velocity", "The  desired velocity of the agent including any potential contribution from avoidance. (Read Only)")] out Vector3 desiredVelocity,
     [FriendlyName("Remaining Distance", "Remaining distance along the current path - or infinity when not known. (Read Only)")] out float remainingDistance,
     [FriendlyName("Base Offset", "The relative vertical displacement of the owning GameObject.")] out float baseOffset,
     [FriendlyName("Is On Off Mesh Link", "Is agent currently positioned on an OffMeshLink. (Read Only)")] out bool isOnOffMeshLink,
     [FriendlyName("Current Off Mesh Link Data", "The current OffMeshLinkData.")] out OffMeshLinkData currentOffMeshLinkData,
     [FriendlyName("Auto Traverse Off Mesh Link", "Automate movement onto and off of OffMeshLinks.")] out bool autoTraverseOffMeshLink,
     [FriendlyName("Auto Repath", "Attempt to acquire a new path if the existing path becomes invalid or if the agent reaches the end of a partial and stale path.")] out bool autoRepath,
     [FriendlyName("Has Path", "Does the agent currently have a path. (Read Only)")] out bool hasPath,
     [FriendlyName("Path Pending", "A path is being computed, but not yet ready. (Read Only)")] out bool pathPending,
     [FriendlyName("Is Path Stale", "Is the current path stale. (Read Only) \n\nWhen true, the path may no longer be valid or optimal. This flag will be set if: there are any changes to the walkableMask, if any OffMeshLink is enabled or disabled, or if the costs for the NavMeshLayers have been changed.")] out bool isPathStale,
     [FriendlyName("Path Status", "Query the state of the current path.")] out NavMeshPathStatus pathStatus,
     [FriendlyName("Path", "Set or get a copy of the current path.")] out NavMeshPath path,
     [FriendlyName("Walkable Mask", "Specifies which NavMesh layers are passable (bitfield). Changing walkableMask will make the path stale (see isPathStale)")] out int walkableMask,
     [FriendlyName("Speed", "Maximum movement speed.")] out float speed,
     [FriendlyName("Angular Speed", "Maximum rotation speed in (deg/s).")] out float angularSpeed,
     [FriendlyName("Acceleration", "Maximum acceleration.")] out float acceleration,
     [FriendlyName("Update Position", "Should the agent update the transform position.")] out bool updatePosition,
     [FriendlyName("Update Rotation", "Should the agent update the transform orientation.")] out bool updateRotation,
     [FriendlyName("Radius", "Agent avoidance radius.")] out float radius,
     [FriendlyName("Height", "Agent height.")] out float height,
     [FriendlyName("Obstacle Avoidance Type", "The level of quality of avoidance.")] out ObstacleAvoidanceType obstacleAvoidanceType
     )
 {
     destination             = agent.destination;
     stoppingDistance        = agent.stoppingDistance;
     velocity                = agent.velocity;
     nextPosition            = agent.nextPosition;
     steeringTarget          = agent.steeringTarget;
     desiredVelocity         = agent.desiredVelocity;
     remainingDistance       = agent.remainingDistance;
     baseOffset              = agent.baseOffset;
     isOnOffMeshLink         = agent.isOnOffMeshLink;
     currentOffMeshLinkData  = agent.currentOffMeshLinkData;
     autoTraverseOffMeshLink = agent.autoTraverseOffMeshLink;
     autoRepath              = agent.autoRepath;
     hasPath               = agent.hasPath;
     pathPending           = agent.pathPending;
     isPathStale           = agent.isPathStale;
     pathStatus            = agent.pathStatus;
     path                  = agent.path;
     walkableMask          = agent.walkableMask;
     speed                 = agent.speed;
     angularSpeed          = agent.angularSpeed;
     acceleration          = agent.acceleration;
     updatePosition        = agent.updatePosition;
     updateRotation        = agent.updateRotation;
     radius                = agent.radius;
     height                = agent.height;
     obstacleAvoidanceType = agent.obstacleAvoidanceType;
 }
Exemplo n.º 29
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);
    }
    // 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;
        }
    }