Beispiel #1
0
        protected void FixedUpdate()
        {
            if (!CacheMonsterCharacterEntity.IsServer)
            {
                return;
            }

            if (isStopped)
            {
                CacheRigidbody2D.velocity = Vector2.zero;
                return;
            }

            if (currentDestination.HasValue)
            {
                var currentPosition = new Vector2(CacheTransform.position.x, CacheTransform.position.y);
                moveDirection = (currentDestination.Value - currentPosition).normalized;
                if (Vector3.Distance(currentDestination.Value, currentPosition) < stoppingDistance)
                {
                    StopMove();
                }
                else
                {
                    CacheMonsterCharacterEntity.UpdateCurrentDirection(moveDirection);
                    CacheRigidbody2D.velocity = moveDirection * speed;
                }
            }
        }
Beispiel #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);
                }
            }
        }