private IEnumerator ChaseCoroutine()
    {
        while (currentState == BrainState.Chasing)
        {
            if (followBody != null && followBody.Visible == true)
            {
                float horizontalToTarget = Vector2.Dot(followBody.transform.position - transform.position, transform.right);

                if (horizontalToTarget > detectionWidth / 2f && CheckRight() != DetectionResult.Avoid)
                {
                    if (walker.currentWalkDirection == -1)
                    {
                        currentState = BrainState.Thinking;
                    }
                    else
                    {
                        walker.Walk(1);
                    }
                }
                else if (horizontalToTarget < -detectionWidth / 2f && CheckLeft() != DetectionResult.Avoid)
                {
                    if (walker.currentWalkDirection == 1)
                    {
                        currentState = BrainState.Thinking;
                    }
                    else
                    {
                        walker.Walk(-1);
                    }
                }
                else
                {
                    if (CheckAbove() != DetectionResult.Avoid)
                    {
                        jumper.Jump();
                    }

                    currentState = BrainState.Thinking;
                }
            }
            else
            {
                currentState = BrainState.Thinking;
            }

            yield return(new WaitForFixedUpdate());
        }

        currentStateCoroutine = null;
        StateCoroutineSwitch();
    }
Exemple #2
0
    public void Update()
    {
        remainingPatrolTime -= Time.deltaTime;

        //there's still patrol time left, so accelerate in our patrol direction
        if (remainingPatrolTime > 0.0f)
        {
            controlledMover.AccelerateInDirection(new Vector2(movementDirection, 0.0f));
        }
        //we're out of patrol time, so if we've come to rest by now, reverse direction and continue
        else if (!controlledMover.IsWalking())
        {
            movementDirection *= -1;

            remainingPatrolTime = patrolTime;

            if (jumpsAtEnd)
            {
                Jumper jumper = controlledMover.GetComponent <Jumper>();
                if (jumper != null)
                {
                    jumper.Jump();
                }
            }
        }
    }
Exemple #3
0
 void Update()
 {
     if (Input.GetButtonDown("Jump"))
     {
         _jumper.Jump();
     }
 }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        //Moving Left
        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
        {
            mover.AccelerateInDirection(new Vector2(-1f, 0f));
            projectileShooter.SetDirection(new Vector3(-1f, 0f));
            //spriteRenderer.flipX = true;
            transform.rotation = Quaternion.Euler(transform.rotation.x, 180f, transform.rotation.z);
            animator.SetBool("running", true);
        }

        //Moving Right
        if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
        {
            mover.AccelerateInDirection(new Vector2(1f, 0f));
            projectileShooter.SetDirection(new Vector3(1f, 0f));
            //spriteRenderer.flipX = false;
            transform.rotation = Quaternion.Euler(transform.rotation.x, 0f, transform.rotation.z);
            animator.SetBool("running", true);
        }


        // Moving Up
        if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W))
        {
            jumper.Jump();
        }

        // If no keys are pressed let the animator know
        if (Input.anyKey == false)
        {
            animator.SetBool("running", false);
        }
    }
Exemple #5
0
    private void Update()
    {
        if (!gl.mainHero.IsAlife)
        {
            SceneManager.LoadScene("Died");
        }
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            StartCoroutine(SpiritDash.SpiritPath(this));
            _rigidBody.velocity        = Vector3.zero;
            _rigidBody.angularVelocity = 0;
        }

        if (EnableMove)
        {
            float axis      = Input.GetAxis("Horizontal");
            float derection = Input.GetAxisRaw("Horizontal");

            if (derection != 0)
            {
                var nd = axis > 0 ? Derection.Right : Derection.Left;
                if (nowDerection != nd)
                {
                    scale.x     *= -1;
                    nowDerection = nd;
                }
                transform.localScale = scale;
            }


            _rigidBody.transform.position += new Vector3(axis, 0) * 0.05f;
#if MYDEBUG
            if (Input.GetKeyDown(KeyCode.J))
            {
                Jumper.Inc();
            }

            if (Input.GetKeyDown(KeyCode.Q))
            {
                SpiritDash.Enabled = true;
            }

            if (Input.GetKeyDown(KeyCode.K))
            {
                Dasher.Enabled = true;
            }
#endif
            if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                Dasher.Dash(_rigidBody, nowDerection);
            }


            if (Input.GetKeyDown(KeyCode.Space))
            {
                StartCoroutine(Jumper.Jump(_rigidBody));
            }
        }
    }
Exemple #6
0
    private void FixedUpdate()
    {
        xMover.Move(rb2d);
        dashMover.Dash(rb2d);
        jumper.Jump(rb2d);

        ImproveFallsAndUps();
    }
Exemple #7
0
    public void Update()
    {
        if (Time.time >= nextJumpTime)
        {
            controlledJumper.Jump();

            nextJumpTime = Time.time + jumpDelay;
        }
    }
    // Update is called once per frame
    void Update()
    {
        jumpTimer += Time.deltaTime;

        if (jumpTimer >= timeBetweenJumps)
        {
            jumper.Jump();
            jumpTimer = 0;
        }
    }
    public void Jump()
    {
        if (transform.position.x < 34.0f || transform.position.x > 46.0f)
        {
            return;
        }

        m_jumper.Jump();
        OnJump();
    }
Exemple #10
0
    public void Update()
    {
        //we can use the convenience of Unity's input axes to get direction automatically.
        //bonus! this works with WASD and we can hook it up to work with controllers!
        controlledMover.AccelerateInDirection(new Vector3(Input.GetAxis("Horizontal"), 0.0f, 0.0f));

        if (Input.GetButtonDown("Jump"))
        {
            controlledJumper.Jump();
        }
    }
Exemple #11
0
 private void Jump()
 {
     if (Input.GetButtonDown("Jump"))
     {
         _jumper.Jump(true);
         _animator.ResetTrigger("Land");
         _animator.SetTrigger("Jump");
     }
     else if (Input.GetButtonUp("Jump"))
     {
         _animator.ResetTrigger("Jump");
         _animator.SetTrigger("Land");
     }
 }
Exemple #12
0
 /// <summary>
 /// Makes this agent jump
 /// </summary>
 public void MakeJump()
 {
     jumper.Jump();
 }
Exemple #13
0
 private IEnumerator JumpTo(Vector3 endPos, Vector3 forward)
 {
     yield return(jumper.Jump(endPos, forward, 0.3f, climbJumpGravity));
 }
Exemple #14
0
    // Update is called once per frame
    void Update()
    {
        //Check if character just landed on the ground
        var checkGrounded = IsGrounded();

        if (!m_grounded && checkGrounded)
        {
            m_grounded = true;
            m_animator.SetBool("Grounded", m_grounded);
        }

        //Check if character just started falling
        if (m_grounded && !checkGrounded)
        {
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
        }

        // -- Handle input and movement --
        float inputX = Input.GetAxis("Horizontal");

        // Swap direction of sprite depending on walk direction
        if (inputX > 0)
        {
            transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f);
        }
        else if (inputX < 0)
        {
            transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
        }

        float inputY = Input.GetAxis("Vertical");

        // Move
        Run(inputX, inputY);

        //Set AirSpeed in animator
        float verticalSpeed = jumper.GetVerticalSpeed();

        m_animator.SetFloat("AirSpeed", verticalSpeed);

        // -- Handle Animations --
        //Death
        if (Input.GetKeyDown("e"))
        {
            if (!m_isDead)
            {
                m_animator.SetTrigger("Death");
            }
            else
            {
                m_animator.SetTrigger("Recover");
            }

            m_isDead = !m_isDead;
        }

        //Hurt
        else if (Input.GetKeyDown("q"))
        {
            m_animator.SetTrigger("Hurt");
        }

        //Attack
        else if (Input.GetButtonDown("Action") || Input.GetKeyDown(KeyCode.KeypadEnter))
        {
            m_animator.SetTrigger("Attack");
        }

        //Change between idle and combat idle
        else if (Input.GetKeyDown("f"))
        {
            m_combatIdle = !m_combatIdle;
        }

        //Jump
        else if (Input.GetButtonDown("Jump") && m_grounded)
        {
            m_animator.SetTrigger("Jump");
            m_grounded = false;
            m_animator.SetBool("Grounded", m_grounded);
            jumper.Jump(m_jumpForce);
        }

        //Run
        else if (Mathf.Abs(inputX) > Mathf.Epsilon || Mathf.Abs(inputY) > Mathf.Epsilon)
        {
            m_animator.SetInteger("AnimState", 2);
        }

        //Combat Idle
        else if (m_combatIdle)
        {
            m_animator.SetInteger("AnimState", 1);
        }

        //Idle
        else
        {
            m_animator.SetInteger("AnimState", 0);
        }
    }