public void UpdateAttackTarget(float time, Vector3 currentPosition, BaseCharacterEntity targetEntity)
        {
            // If it has target then go to target
            Vector3 targetEntityPosition = targetEntity.CacheTransform.position;
            float   attackDistance       = CacheMonsterCharacterEntity.GetAttackDistance(false);

            attackDistance -= attackDistance * 0.1f;
            attackDistance -= CacheNavMeshAgent.stoppingDistance;
            if (Vector3.Distance(currentPosition, targetEntityPosition) <= attackDistance)
            {
                StopMove();
                SetStartFollowTargetTime(time);
                // Lookat target then do anything when it's in range
                Vector3 lookAtDirection = (targetEntityPosition - currentPosition).normalized;
                // slerp to the desired rotation over time
                if (lookAtDirection.magnitude > 0)
                {
                    Vector3 lookRotationEuler = Quaternion.LookRotation(lookAtDirection).eulerAngles;
                    lookRotationEuler.x = 0;
                    lookRotationEuler.z = 0;
                    CacheMonsterCharacterEntity.CacheTransform.rotation = Quaternion.RotateTowards(CacheMonsterCharacterEntity.CacheTransform.rotation, Quaternion.Euler(lookRotationEuler), CacheNavMeshAgent.angularSpeed * Time.deltaTime);
                }
                CacheMonsterCharacterEntity.RequestAttack(false, targetEntity.OpponentAimTransform.position);
                // TODO: Random to use skills
            }
            else
            {
                // Following target
                if (oldDestination != targetEntityPosition &&
                    time - setDestinationTime >= setTargetDestinationDelay)
                {
                    SetDestination(time, targetEntityPosition);
                }
                // Stop following target
                if (time - startFollowTargetTime >= followTargetDuration)
                {
                    RandomWanderTarget(time);
                }
            }
        }
Esempio n. 2
0
        public void UpdateAttackTarget(float time, Vector3 currentPosition, BaseCharacterEntity targetEntity)
        {
            // If it has target then go to target
            var targetEntityPosition = targetEntity.CacheTransform.position;
            var attackDistance       = CacheMonsterCharacterEntity.GetAttackDistance();

            attackDistance -= attackDistance * 0.1f;
            attackDistance -= stoppingDistance;
            if (Vector3.Distance(currentPosition, targetEntityPosition) <= attackDistance)
            {
                StopMove();
                SetStartFollowTargetTime(time);
                // Lookat target then do anything when it's in range
                var targetDirection = (targetEntity.CacheTransform.position - CacheMonsterCharacterEntity.CacheTransform.position).normalized;
                if (targetDirection.magnitude != 0f)
                {
                    CacheMonsterCharacterEntity.UpdateCurrentDirection(targetDirection);
                }
                CacheMonsterCharacterEntity.RequestAttack();
                // TODO: Random to use skills
            }
            else
            {
                // Following target
                if (oldDestination != targetEntityPosition &&
                    time - setDestinationTime >= setTargetDestinationDelay)
                {
                    SetDestination(time, targetEntityPosition);
                }
                // Stop following target
                if (time - startFollowTargetTime >= followTargetDuration)
                {
                    RandomWanderTarget(time);
                }
            }
        }