Example #1
0
 void switchstate()
 {
     if (space > 30)
     {
         currentbehaviour = BEHAVIOUR.E_EXPAND;
         return;
     }
     if (dmg > 50)
     {
         currentbehaviour = BEHAVIOUR.E_DEFEND;
         return;
     }
     else
     {
         currentbehaviour = BEHAVIOUR.E_NULL;
         return;
     }
 }
Example #2
0
    //Runs until player is outside the collider for a set amount of time.
    //I fall detta behöver läggas till på spårade objekt så borde detta göras före och efter while-loopen
    IEnumerator RunAway(Transform target, float time, float radius)
    {
        //consider locking if this shit actually becomes complex to the point where you regrett not making a state machine
        _behaviour = BEHAVIOUR.FLEEING;
        float timeLeft = time;
        float gravity  = 0;

        _particles.gameObject.SetActive(true); //Throw dirt

        while (timeLeft > 0)
        {
            Vector3 direction = (this.transform.position - target.transform.position).normalized;
            direction.y = gravity;

            FaceAwayFromTarget(target);
            if (_charCon.isGrounded && _charCon.velocity.y < 0)
            {
                gravity = -2;
            }
            //Add sine wave to movemnt direction
            Vector3 rotatedDir = rotateVec3(direction, Mathf.Sin(Time.time) * 0.5f);

            _charCon.Move(rotatedDir * _speed * Time.deltaTime);
            gravity += _gravity * Time.deltaTime;

            //If player is inside trigger
            if (Vector3.Distance(transform.position, target.position) < radius)
            {
                timeLeft = time;
            }
            else
            {
                timeLeft -= Time.deltaTime;
            }
            yield return(null);
        }
        _particles.gameObject.SetActive(false);
        _behaviour = BEHAVIOUR.IDLE;
        float y = transform.eulerAngles.y;

        transform.eulerAngles = new Vector3(0, y, 0);
    }
Example #3
0
 private void RecoverFromStun()
 {
     behaviour = initialBehaviour;
 }
Example #4
0
 void Awake()
 {
     initialBehaviour = behaviour;
     spriteRenderer   = GetComponent <SpriteRenderer>();
 }
Example #5
0
 public void Stun()
 {
     behaviour = BEHAVIOUR.NEUTRAL;
     Invoke("RecoverFromStun", stunTime);
 }