Esempio n. 1
0
        void DoMove()
        {
            if (_agent == null)
            {
                return;
            }

            _agent.Move(offset.Value);
        }
        public override TaskStatus OnUpdate()
        {
            if (navMeshAgent == null)
            {
                Debug.LogWarning("NavMeshAgent is null");
                return(TaskStatus.Failure);
            }

            navMeshAgent.Move(offset.Value);

            return(TaskStatus.Success);
        }
        void DoKnockBackAction()
        {
            var go = Fsm.GetOwnerDefaultTarget(knockThisBack);

            if (go == null)
            {
                return;
            }

            int eValue = (int)type;

            switch (eValue)
            {
            case 0:
                // navmesh
                nav    = go.GetComponent <UnityEngine.AI.NavMeshAgent>();
                npcPos = go.transform.position;
                Vector3 direction1 = (npcPos - hitPoint.Value).normalized;
                direction1 = direction1 * knockBackAmount.Value / 2;
                direction1 = new Vector3(direction1.x, 0f, direction1.z);
                nav.Move(direction1);


                break;

            case 1:
                // rb
                rb     = go.GetComponent <Rigidbody>();
                npcPos = go.transform.position;
                Vector3 direction = (npcPos - hitPoint.Value).normalized;
                direction = direction * knockBackAmount.Value;
                direction = new Vector3(direction.x, 0f, direction.z);
                rb.AddForce(direction, ForceMode.VelocityChange);

                break;

            case 2:
                // cc
                cc     = go.GetComponent <CharacterController>();
                npcPos = go.transform.position;
                Vector3 direction2 = (npcPos - hitPoint.Value).normalized;
                direction2 = direction2 * knockBackAmount.Value * 10f;
                direction2 = new Vector3(direction2.x, 0f, direction2.z);
                cc.Move(direction2 * Time.deltaTime);

                break;
            }
        }
Esempio n. 4
0
        void Move()
        {
            Transform cameratransform = Camera.main.transform;

            cameratransform.rotation = Quaternion.LookRotation(new Vector3(transform.position.x - cameratransform.position.x, 0, transform.position.z - cameratransform.position.z));
            Vector3 forward = cameratransform.TransformDirection(Vector3.forward);
            Vector3 right   = cameratransform.TransformDirection(Vector3.right);

            playerDirection = Input.GetAxis("Horizontal") * right + Input.GetAxis("Vertical") * forward;
            speed           = playerDirection.magnitude;

            if (Input.GetKey("left shift") || Input.GetKey("right shift"))
            {
                //walking(+Shift Key)
                if (speedWeight > 0.2f)
                {
                    speedWeight -= Time.deltaTime * 2.0f;
                }
                else
                {
                    speedWeight = 0.2f;
                }
            }
            else
            {
                //running
                if (speedWeight < 1.0f)
                {
                    speedWeight += Time.deltaTime * 2.0f;
                }
                else
                {
                    speedWeight = 1.0f;
                }
            }
            speed = speed * speedWeight;
            if (speed > 0)
            {
                if (playerDirection != Vector3.zero)
                {
                    Quaternion playerRotation = Quaternion.LookRotation(playerDirection);
                    transform.rotation = Quaternion.Lerp(transform.rotation, playerRotation, Time.deltaTime * lerpSpeed);
                }
                agent.Move(transform.forward * Time.deltaTime * speed * 3.0f);
            }
            animator.SetFloat("speed", speed);
        }
Esempio n. 5
0
        public virtual void MoveForwardToTarget(float dt)
        {
            m_Direction = targetPosition - currentTransform.position;
            m_Angle     = Mathf.Atan2(m_Direction.x, m_Direction.z) * Mathf.Rad2Deg;
            var position = m_Direction.normalized * m_Target.GetMoveSpeed() * dt;

            if (m_NavMeshAgent.isOnNavMesh)
            {
                position *= 0.5f;
                m_NavMeshAgent.Move(position);
            }
            else
            {
                currentTransform.position = Vector3.Lerp(currentTransform.position, currentTransform.position + position, 0.5f);
            }
            currentTransform.rotation = Quaternion.Lerp(currentTransform.rotation, Quaternion.AngleAxis(m_Angle, Vector3.up), 0.5f);
#if UNITY_EDITOR
            Debug.DrawRay(currentTransform.position, m_Direction, Color.green);
#endif
            Reset();
        }