Exemple #1
0
    // Use this for initialization
    void Start()
    {
        //Get the player by default
        if (!currentTarget)
        {
            currentTarget = GameObject.FindWithTag("PlayerWarrior");
        }

        targetTransform = currentTarget.transform;

        previousState = EnemyMovementState.NONE;
        currentState  = EnemyMovementState.MOVING;
        this.GetComponentInChildren <Animator>().SetBool("Walking", true);


        DelayedRandomTime *= Random.value;
        currentTime        = 0f;


        //Initialize "infinite" positions array
        InfitePoint    = new Vector3[numberDirections];
        InfitePoint[0] = new Vector3(-100000f, 0, 0);        //LEFT
        InfitePoint[1] = new Vector3(100000f, 0, 0);         //RIGHT
        InfitePoint[2] = new Vector3(0, 100000f, 0);         //UP
        InfitePoint[3] = new Vector3(0, -100000f, 0);        //DOWN
        //InfitePoint[4] = new Vector3(-100000f, 100000f, 0);
        //InfitePoint[5] = new Vector3(-100000f, -100000f, 0);
        //InfitePoint[6] = new Vector3(100000f, -100000f, 0);
        //InfitePoint[7] = new Vector3(100000f, 100000f, 0);

        //Initialize in a random direction
        currentDirection = InfitePoint[Mathf.FloorToInt(Random.value * numberDirections)];
    }
Exemple #2
0
 // Update is called once per frame
 protected override void Update()
 {
     //		float time_delta_fraction = Time.deltaTime / (1.0f / Application.targetFrameRate);
     base.Update();
     base.BehaviorStateMathine.Update();
     if (base.BehaviorStateMathine.IsFinished())
     {
         if (movingState == GelState.move)
         {
             movingState = GelState.stop;
             State normalMovementState = new EnemyMovementState(this, this.transform.position, speed);
             base.BehaviorStateMathine.ChangeState(normalMovementState);
         }
         else
         {
             movingState = GelState.move;
             int randNum = Random.Range(0, 100);
             if (!currentMovingTowardDetector.GetComponent <Detector> ().CollideWithTile() && randNum >= changeDirectionProb * 100)
             {
                 State normalMovementState = new EnemyMovementState(this, currentMovingTowardDetector.transform.position, speed);
                 base.BehaviorStateMathine.ChangeState(normalMovementState);
             }
             else
             {
                 State normalMovementState = new EnemyMovementState(this, randomTakeStep(), speed);
                 base.BehaviorStateMathine.ChangeState(normalMovementState);
             }
         }
     }
 }
Exemple #3
0
    // Use this for initialization
    protected override void Start()
    {
        stoped = false;
        State normalMovementState = new EnemyMovementState(this, randomTakeStep(), speed);

        base.BehaviorStateMathine.ChangeState(normalMovementState);
    }
Exemple #4
0
	void OnCollisionEnter(Collision coll) {
		if (coll.gameObject.tag == "Tiles") {
			movingState = GelState.stop;
			State normalMovementState = new EnemyMovementState (this, transform.position, speed);
			base.BehaviorStateMathine.ChangeState (normalMovementState);
		}
	}
    void Awake()
    {
        // Extract positions of patrol gameobjects for patrolling positions
        foreach (GameObject patrolObj in patrolObjs)
        {
            patrolPositions.Add(patrolObj.transform.position);
        }

        // Ensure patrol positions has at least one element
        // By default, use enemy's original position
        if (patrolPositions.Count == 0)
        {
            patrolPositions.Add(gameObject.transform.position);
        }
        else if (patrolPositions.Count == 1 && patrolPositions[0] == Vector3.zero)
        {
            patrolPositions[0] = gameObject.transform.position;
        }

        if (patrolPositions.Count > 1)
        {
            patrols            = true;
            moveState          = EnemyMovementState.Patrolling;
            curPatrolDestIndex = 0;
            curPatrolDest      = patrolPositions[curPatrolDestIndex];
            agent.SetDestination(curPatrolDest);
        }
    }
Exemple #6
0
        public void SetTarget(Transform newTarget)
        {
            target           = newTarget;
            stoppingDistance = 0;
            _navMeshAgent.stoppingDistance = stoppingDistance;

            _currentMovementState = EnemyMovementState.FollowingTarget;
        }
Exemple #7
0
 void OnCollisionEnter(Collision coll)
 {
     if (coll.gameObject.tag == "Tiles")
     {
         State normalMovementState = new EnemyMovementState(this, randomTakeStep(), speed);
         base.BehaviorStateMathine.ChangeState(normalMovementState);
     }
 }
Exemple #8
0
 void OnCollisionEnter(Collision coll)
 {
     if (coll.gameObject.tag == "Tiles")
     {
         movingState = GelState.stop;
         State normalMovementState = new EnemyMovementState(this, transform.position, speed);
         base.BehaviorStateMathine.ChangeState(normalMovementState);
     }
 }
Exemple #9
0
        public void SetStaticPosition(Vector3 newStartingPosition)
        {
            staticPosition        = newStartingPosition;
            _currentMovementState = EnemyMovementState.GoingToStaticTarget;

            if (_navMeshAgent)
            {
                _navMeshAgent.destination = staticPosition;
            }
        }
    public void Aggro()
    {
        // If enemy is always passive, don't make it aggressive or follow player
        if (enemyState == EnemyState.AlwaysPassive)
        {
            return;
        }

        enemyState = EnemyState.Aggro;
        moveState  = EnemyMovementState.Following;
    }
Exemple #11
0
    // Update is called once per frame
    protected override void Update()
    {
        //		float time_delta_fraction = Time.deltaTime / (1.0f / Application.targetFrameRate);
        base.Update();
        if (state != GoriyaState.stop)
        {
            base.BehaviorStateMathine.Update();
            animationCounter++;
            animationCounter %= 30;
            GetComponent <SpriteRenderer> ().sprite = Sprites [2 * currentMovingTowardDetectorInd + animationCounter / 15];


            if (base.BehaviorStateMathine.IsFinished())
            {
                int randNum = Random.Range(0, 100);
                if (state == GoriyaState.move && randNum < attackProb * 100)
                {
                    state = GoriyaState.attack;
                    Vector3 velocity = (currentMovingTowardDetector.transform.position - transform.position).normalized * 5;
                    velocity.z = 0;
                    State attackState = new GoriyaAttackState(this, boomerang, velocity);
                    base.BehaviorStateMathine.ChangeState(attackState);
                }
                else
                {
                    state   = GoriyaState.move;
                    randNum = Random.Range(0, 100);
                    if (!currentMovingTowardDetector.GetComponent <Detector> ().CollideWithTile() && randNum >= changeDirectionProb * 100)
                    {
                        State normalMovementState = new EnemyMovementState(this, currentMovingTowardDetector.transform.position, speed);
                        base.BehaviorStateMathine.ChangeState(normalMovementState);
                    }
                    else
                    {
                        State normalMovementState = new EnemyMovementState(this, randomTakeStep(), speed);
                        base.BehaviorStateMathine.ChangeState(normalMovementState);
                    }
                }
            }
        }
        else
        {
            if (Time.time - stun_start_time > 5)
            {
                state = state_mem;
            }
        }
    }
Exemple #12
0
    // Update is called once per frame
    protected override void Update()
    {
        if (!stoped)
        {
            counter++;
            if (counter < 5)
            {
                this.gameObject.GetComponent <SpriteRenderer> ().sprite = Stal_sprites [0];
            }
            else if (counter >= 5 && counter < 10)
            {
                this.gameObject.GetComponent <SpriteRenderer> ().sprite = Stal_sprites [1];
            }
            if (counter == 10)
            {
                counter = 0;
            }
//		float time_delta_fraction = Time.deltaTime / (1.0f / Application.targetFrameRate);
            base.Update();
            base.BehaviorStateMathine.Update();
            if (base.BehaviorStateMathine.IsFinished())
            {
                int randNum = Random.Range(0, 100);
                if (!currentMovingTowardDetector.GetComponent <Detector> ().CollideWithTile() && randNum >= changeDirectionProb * 100)
                {
                    State normalMovementState = new EnemyMovementState(this, currentMovingTowardDetector.transform.position, speed);
                    base.BehaviorStateMathine.ChangeState(normalMovementState);
                }
                else
                {
                    State normalMovementState = new EnemyMovementState(this, randomTakeStep(), speed);
                    base.BehaviorStateMathine.ChangeState(normalMovementState);
                }
            }
        }
        else
        {
            if (Time.time - stun_start_time > 5)
            {
                stoped = false;
            }
        }
    }
Exemple #13
0
 private void CheckIfReachedTarget()
 {
     if (!_navMeshAgent.pathPending)
     {
         if (_navMeshAgent.remainingDistance <= _navMeshAgent.stoppingDistance)
         {
             if (!_navMeshAgent.hasPath || _navMeshAgent.velocity.sqrMagnitude == 0f)
             {
                 if (_invokedTargetReachedEvent)
                 {
                     _currentMovementState = EnemyMovementState.FollowingTarget;
                 }
                 else
                 {
                     _currentMovementState      = EnemyMovementState.Idling;
                     _invokedTargetReachedEvent = true;
                 }
                 TargetReached?.Invoke(this, EventArgs.Empty);
             }
         }
     }
 }
Exemple #14
0
	// Update is called once per frame
	protected override void Update ()
	{
		//		float time_delta_fraction = Time.deltaTime / (1.0f / Application.targetFrameRate);
		base.Update ();
		base.BehaviorStateMathine.Update ();
		if (base.BehaviorStateMathine.IsFinished()) {
			if (movingState == GelState.move) {
				movingState = GelState.stop;
				State normalMovementState = new EnemyMovementState (this, this.transform.position, speed);
				base.BehaviorStateMathine.ChangeState (normalMovementState);
			} else {
				movingState = GelState.move;
				int randNum = Random.Range (0, 100);
				if (!currentMovingTowardDetector.GetComponent<Detector> ().CollideWithTile () && randNum >= changeDirectionProb * 100) {
					State normalMovementState = new EnemyMovementState (this, currentMovingTowardDetector.transform.position, speed);
					base.BehaviorStateMathine.ChangeState (normalMovementState);
				} else {
					State normalMovementState = new EnemyMovementState (this, randomTakeStep (), speed);
					base.BehaviorStateMathine.ChangeState (normalMovementState);
				}
			}
		}
	}
Exemple #15
0
	// Update is called once per frame
	protected override void Update ()
	{
		//		float time_delta_fraction = Time.deltaTime / (1.0f / Application.targetFrameRate);
		base.Update ();
		if (state != GoriyaState.stop) {
			base.BehaviorStateMathine.Update ();
			animationCounter++;
			animationCounter %= 30;
			GetComponent<SpriteRenderer> ().sprite = Sprites [2 * currentMovingTowardDetectorInd + animationCounter / 15];


			if (base.BehaviorStateMathine.IsFinished ()) {
				int randNum = Random.Range (0, 100);
				if (state == GoriyaState.move && randNum < attackProb * 100) {
					state = GoriyaState.attack;
					Vector3 velocity = (currentMovingTowardDetector.transform.position - transform.position).normalized * 5;
					velocity.z = 0;
					State attackState = new GoriyaAttackState (this, boomerang, velocity);
					base.BehaviorStateMathine.ChangeState (attackState);
				} else {
					state = GoriyaState.move;
					randNum = Random.Range (0, 100);
					if (!currentMovingTowardDetector.GetComponent<Detector> ().CollideWithTile () && randNum >= changeDirectionProb * 100) {
						State normalMovementState = new EnemyMovementState (this, currentMovingTowardDetector.transform.position, speed);
						base.BehaviorStateMathine.ChangeState (normalMovementState);
					} else {
						State normalMovementState = new EnemyMovementState (this, randomTakeStep (), speed);
						base.BehaviorStateMathine.ChangeState (normalMovementState);
					}
				}
			}
		} else {
			if (Time.time - stun_start_time > 5) {
				state = state_mem;
			}
		}
	}
Exemple #16
0
	// Update is called once per frame
	protected override void Update ()
	{
		if (!stoped) {
			counter++;
			if (counter < 5) {
				this.gameObject.GetComponent<SpriteRenderer> ().sprite = Stal_sprites [0];

			} else if (counter >= 5 && counter < 10) {
				this.gameObject.GetComponent<SpriteRenderer> ().sprite = Stal_sprites [1];

			}
			if (counter == 10)
				counter = 0;
//		float time_delta_fraction = Time.deltaTime / (1.0f / Application.targetFrameRate);
			base.Update ();
			base.BehaviorStateMathine.Update ();
			if (base.BehaviorStateMathine.IsFinished ()) {
				int randNum = Random.Range (0, 100);
				if (!currentMovingTowardDetector.GetComponent<Detector> ().CollideWithTile () && randNum >= changeDirectionProb * 100) {
				
					State normalMovementState = new EnemyMovementState (this, currentMovingTowardDetector.transform.position, speed);
					base.BehaviorStateMathine.ChangeState (normalMovementState);
				 
				} else {
					State normalMovementState = new EnemyMovementState (this, randomTakeStep (), speed);
					base.BehaviorStateMathine.ChangeState (normalMovementState);
				}


			}
		} else {
			if (Time.time - stun_start_time > 5) {
				stoped = false;
			}
		}
	}
    void Update()
    {
        if (enemyState != EnemyState.AlwaysPassive)
        {
            // Only look for player if aggro'd, not knockedBack, and not leashing
            if (enemyState == EnemyState.Aggro && !knockedBack && moveState != EnemyMovementState.Leashing)
            {
                if (CanSeePlayer())
                {
                    Vector3 playerPos = GameManager.GM.GetPlayer().transform.position;
                    agent.SetDestination(playerPos);
                    moveState = EnemyMovementState.Following;
                }
            }

            if (moveState == EnemyMovementState.Following)
            {
                UpdatePatrolDestination();
                float distFromLeash = Vector3.Distance(gameObject.transform.position, curPatrolDest);

                if (distFromLeash > maxLeashDistance)
                {
                    moveState = EnemyMovementState.Leashing;
                    agent.SetDestination(curPatrolDest);
                }
            }
            else if (moveState == EnemyMovementState.Leashing)
            {
                UpdatePatrolDestination();
                float distFromLeash = Vector3.Distance(gameObject.transform.position, curPatrolDest);

                if (distFromLeash < minLeashDistance)
                {
                    moveState = EnemyMovementState.Resetting;
                }
            }
            else if (moveState == EnemyMovementState.Resetting)
            {
                if (ReachedDestination())
                {
                    if (patrols)
                    {
                        moveState = EnemyMovementState.Patrolling;
                        UpdatePatrolDestination();
                        agent.SetDestination(curPatrolDest);
                    }
                    else
                    {
                        moveState = EnemyMovementState.Idle;
                    }
                }
            }
        }

        // Not part of same else if chain because state can change to Patrolling and we want it to start
        // patrolling immediately.
        if (moveState == EnemyMovementState.Patrolling)
        {
            if (ReachedDestination())
            {
                curPatrolDestIndex = (curPatrolDestIndex + 1) % patrolPositions.Count;
                curPatrolDest      = patrolPositions[curPatrolDestIndex];
                agent.SetDestination(curPatrolDest);
            }
        }
    }
Exemple #18
0
	// Use this for initialization
	protected override void Start () {
		movingState = GelState.move;
		State normalMovementState = new EnemyMovementState (this, randomTakeStep(), speed);
		base.BehaviorStateMathine.ChangeState (normalMovementState);
	}
Exemple #19
0
 private void Start()
 {
     enemyMovement = transform.root.GetComponent <EnemyMovementState>();
     eStats        = transform.root.GetComponent <EnemyStatsContainer>().eStats;
 }
Exemple #20
0
	void OnCollisionEnter(Collision coll) {
		if (coll.gameObject.tag == "Tiles") {
			state = GoriyaState.move;
			State normalMovementState = new EnemyMovementState (this, randomTakeStep(), speed);
			base.BehaviorStateMathine.ChangeState (normalMovementState);
		}
	}
Exemple #21
0
    // Update is called once per frame
    void Update()
    {
        currentTime += Time.deltaTime;

        switch (currentState)
        {
        case EnemyMovementState.MOVING:
            //MOVE 1
            //if (targetTransform != null)
            //	MoveToTarget(targetTransform.position);

            //MOVE 2
            if (Random.value < 0.01f)                     //Sometimes change direction
            {
                currentDirection = GetInfinitePoint();
            }
            MoveToRandomDirection();

            //Transition to Next State
            if (currentTime >= (movingTime + DelayedRandomTime))
            {
                currentTime  -= (movingTime + DelayedRandomTime);
                previousState = currentState;
                currentState  = EnemyMovementState.PAUSING;

                //Call Idle Animation
                this.GetComponentInChildren <Animator>().SetBool("Walking", false);
            }
            break;


        case EnemyMovementState.MOVING_AROUND:
            FaceToTarget(MoveToRandomPosition());

            //Transition to Next State
            if (currentTime >= movingAroundTime)
            {
                currentTime  -= movingAroundTime;
                previousState = currentState;
                currentState  = EnemyMovementState.PAUSING;

                //Call Idle Animation
                this.GetComponentInChildren <Animator>().SetBool("Walking", false);

                //restart the pause target
                generateNewRandomTarget = true;
            }
            break;

        case EnemyMovementState.PAUSING:
            //Transition to Next State
            if (currentTime >= pauseTime)
            {
                currentTime -= pauseTime;
                if (previousState == EnemyMovementState.MOVING)
                {
                    previousState = currentState;
                    currentState  = EnemyMovementState.MOVING_AROUND;
                }
                else if (previousState == EnemyMovementState.MOVING_AROUND)
                {
                    previousState = currentState;
                    currentState  = EnemyMovementState.MOVING;
                }

                //Call Moving Animation
                this.GetComponentInChildren <Animator>().SetBool("Walking", true);
            }
            break;

        default:
            break;
        }


        ///HACK PARA CAMBIAR DE OBJETIVO CUANDO
        /// LE METAMOS UN NUEVO GAMEOBJECT EN EL retargetHACK
        if (retargetHACK != null)
        {
            Retarget(retargetHACK);
            retargetHACK = null;
        }
    }
	void MoveStop()
	{
		switch(curMovementState)
		{
		case EnemyMovementState.Idel:
			break;
		case EnemyMovementState.BeHit:
			curMovementState = EnemyMovementState.BeHitOver;
			break;
		case EnemyMovementState.Attack:
			curMovementState = EnemyMovementState.AttackOver;
			break;
		case EnemyMovementState.Run:
			curMovementState = EnemyMovementState.RunOver;
			break;
		case EnemyMovementState.Walk:
			curMovementState = EnemyMovementState.WalkOver;
			break;
		}
	}