Exemplo n.º 1
0
        protected void HandlePreviousStateMovement(AIBehaviors fsm, Transform target)
        {
            if (inheritPreviousStateMovement)
            {
                BaseState previousState = fsm.previousState;
                Vector3   destination;
                float     moveSpeed;
                float     rotateSpeed;

                if (previousState == null)
                {
                    destination = GetNextMovement(fsm);
                    moveSpeed   = movementSpeed;
                    rotateSpeed = rotationSpeed;
                }
                else
                {
                    destination = previousState.GetNextMovement(fsm);
                    moveSpeed   = previousState.movementSpeed;
                    rotateSpeed = previousState.rotationSpeed;
                }

                fsm.MoveAgent(destination, moveSpeed, rotateSpeed, target);
            }
            else
            {
                fsm.MoveAgent(target, movementSpeed, rotationSpeed);
            }
        }
Exemplo n.º 2
0
        protected override void Init(AIBehaviors fsm)
        {
            goingToReload          = false;
            curAnimPosition        = 0.0f;
            previousSamplePosition = 0.0f;

            if (inheritPreviousStateMovement && fsm.previousState != null)
            {
                fsm.MoveAgent(fsm.previousState.GetNextMovement(fsm), movementSpeed, rotationSpeed);
            }
            else
            {
                fsm.MoveAgent(fsm.transform, 0.0f, rotationSpeed);
            }

            if (attackBasedOn == AttackMode.Animation)
            {
                attackAnimation = fsm.gameObject.GetComponentInChildren <Animation>();

                if (attackAnimation != null && attackAnimation[attackAnimName] != null)
                {
                    initialCullingType          = attackAnimation.cullingType;
                    attackAnimation.cullingType = AnimationCullingType.AlwaysAnimate;
                    animationLength             = attackAnimation[attackAnimName].length;
                }
                else
                {
                    animationLength = 1.0f;
                }
            }
            else
            {
                intervalAttackTime = Time.time + initialAttackTime;
            }
        }
Exemplo n.º 3
0
        protected override void Action(AIBehaviors fsm)
        {
            if (player != null)
            {
                // Rotate towards the target
                fsm.transform.LookAt(new Vector3(player.position.x, transform.position.y, player.position.z));

                direction      = (fsm.transform.position - player.position).normalized;
                direction.y    = 0.0f;
                targetPosition = player.position + (direction * distance);

                // Move back in the opposite direction
                if (navMeshAgent != null)
                {
                    navMeshAgent.updateRotation = false;                    // disable the automatic rotation
                    fsm.MoveAgent(targetPosition, movementSpeed, 0.0f);
                    navMeshAgent.updateRotation = true;                     //when no longer need to step back then go to normal
                }
                else
                {
                    fsm.transform.Translate(direction * Time.deltaTime * movementSpeed, Space.World);
                }
            }

            // No movement check
            if (Time.time > nextCheckHasMovement && !HasMovement(fsm.transform.position))
            {
                fsm.ChangeActiveState(fsm.previousState);
            }

            previousPosition = fsm.transform.position;
        }
Exemplo n.º 4
0
        protected override void Action(AIBehaviors fsm)
        {
            if (!rotatesTowardTarget)
            {
                fsm.MoveAgent(fsm.transform, 0.0f, rotationSpeed);
            }
            else
            {
                Transform target = fsm.GetClosestPlayer(objectFinder.GetTransforms());

                if (target != null)
                {
                    fsm.MoveAgent(target, 0.0f, rotationSpeed);
                }
            }
        }
Exemplo n.º 5
0
        protected override void Init(AIBehaviors fsm)
        {
            fsm.PlayAudio();
            fsm.MoveAgent(fsm.aiTransform, 0.0f, 0.0f);

            destroyTime = Time.time + destroyAfterTime;

            if (changeTag)
            {
                transform.parent.tag = deadTag;
            }

            if (destroyComponents)
            {
                DestroyObjects(componentsToDestroy);
            }

            if (destroyGameObjects)
            {
                DestroyObjects(gameObjectsToDestroy);
            }

            if (destroyColliders)
            {
                DestroyObjects(gameObject.transform.parent.GetComponentsInChildren <Collider>());
            }
        }
Exemplo n.º 6
0
 protected override void Action(AIBehaviors fsm)
 {
     if (seekTarget != null)
     {
         fsm.MoveAgent(GetNextMovement(fsm), movementSpeed, rotationSpeed);
     }
 }
Exemplo n.º 7
0
        protected override void Init(AIBehaviors fsm)
        {
            fsm.PlayAudio();
            fsm.MoveAgent(fsm.transform, 0.0f, 0.0f);

            destroyThis = destroyAfterTime > 0.0f;
            destroyTime = Time.time + destroyAfterTime;
        }
Exemplo n.º 8
0
        protected override void Init(AIBehaviors fsm)
        {
            //playerSystem = new PlayerSystem(this,fsm);

            this.fsm = fsm;
            fsm.SetNavMeshAgentStoppingDistance(attackRange);
            if (fsm.target != null)
            {
                target = fsm.target;
            }

            goingToReload          = false;
            curAnimPosition        = 0.0f;
            previousSamplePosition = 0.0f;

            if (inheritPreviousStateMovement && fsm.previousState != null)
            {
                fsm.MoveAgent(fsm.previousState.GetNextMovement(fsm), movementSpeed, rotationSpeed);
            }
            else
            {
                fsm.MoveAgent(fsm.transform, 0.0f, rotationSpeed);
            }

            if (attackBasedOn == AttackMode.Animation)
            {
                attackAnimation = fsm.gameObject.GetComponentInChildren <Animation>();

                if (attackAnimation != null && attackAnimation[attackAnimName] != null)
                {
                    initialCullingType          = attackAnimation.cullingType;
                    attackAnimation.cullingType = AnimationCullingType.AlwaysAnimate;
                    animationLength             = attackAnimation[attackAnimName].length;
                }
                else
                {
                    animationLength = 1.0f;
                }
            }
            else
            {
                intervalAttackTime = Time.time + initialAttackTime;
            }
        }
Exemplo n.º 9
0
        protected override void Init(AIBehaviors fsm)
        {
            if (inheritPreviousStateMovement && fsm.previousState != null)
            {
                fsm.MoveAgent(fsm.previousState.GetNextMovement(fsm), movementSpeed, rotationSpeed);
            }
            else
            {
                fsm.MoveAgent(fsm.transform, 0.0f, rotationSpeed);
            }

            attackAnimation = fsm.gameObject.GetComponentInChildren <Animation>();

            if (attackAnimation != null && attackAnimation[attackAnimName] != null)
            {
                animationLength = attackAnimation[attackAnimName].length;
            }
            else
            {
                animationLength = 1.0f;
            }
        }
Exemplo n.º 10
0
        protected override void Action(AIBehaviors fsm)
        {
            if (seekTarget != null)
            {
                targetPosition = GetNextMovement(fsm) + GetEncircleOffset();

                fsm.MoveAgent(targetPosition, movementSpeed, rotationSpeed);

                if (Time.time > nextCheckHasMovement && !HasMovement(fsm.transform.position))
                {
                    fsm.ChangeActiveState(noMovementState);
                }
            }

            previousPosition = fsm.transform.position;
        }
Exemplo n.º 11
0
        protected override void Action(AIBehaviors fsm)
        {
            if (seekTarget != null)
            {
                targetPosition = GetNextMovement(fsm);

                if (HasMovement(fsm.transform.position))
                {
                    fsm.MoveAgent(targetPosition, movementSpeed, rotationSpeed);
                }
                else
                {
                    fsm.ChangeActiveState(noMovementState);
                }
            }

            previousPosition = fsm.transform.position;
        }
Exemplo n.º 12
0
        protected override void Action(AIBehaviors fsm)
        {
            targetPosition = GetNextMovement(fsm);

            fsm.MoveAgent(targetPosition, movementSpeed, rotationSpeed);

            if (Time.time > nextCheckHasMovement && !HasMovement(fsm.transform.position))
            {
                targetPosition = GetTargetPoint(fsm);
            }

            // Target reached
            if (Vector3.SqrMagnitude(transform.position - targetPosition) < sqrDistanceToTargetThreshold)
            {
                HandleTargetReached(fsm);
            }

            previousPosition = fsm.transform.position;
        }
Exemplo n.º 13
0
        protected override void Init(AIBehaviors fsm)
        {
            fsm.PlayAudio();
            fsm.MoveAgent(fsm.transform, 0.0f, 0.0f);

            destroyTime = Time.time + destroyAfterTime;

            if (changeTag)
            {
                transform.parent.tag = deadTag;
            }

            if (componentsToDestroy.Length > 0)
            {
                DestroyComponents();
            }

            if (destroyColliders)
            {
                DestroyColliders();
            }
        }
Exemplo n.º 14
0
 protected override void Action(AIBehaviors fsm)
 {
     fsm.MoveAgent(fsm.currentDestination, movementSpeed, rotationSpeed);
 }
Exemplo n.º 15
0
 protected override void Action(AIBehaviors fsm)
 {
     fsm.MoveAgent(fsm.transform.position, 0.0f, 0.0f);
 }
Exemplo n.º 16
0
 protected override void Action(AIBehaviors fsm)
 {
     fsm.MoveAgent(helpPoint, movementSpeed, rotationSpeed);
 }