コード例 #1
0
        /// <summary> Main cpu play routines </summary>
        protected virtual void CpuMoveToBall()
        {
            if (!characterSkill.canUseSkills)
            {
                return;
            }

            if (player != null)
            {
                float angel = Vector3.Angle(transform.forward, player.transform.position - transform.position);

                // Player if back this IA
                if (Mathf.Abs(angel) > 90 || !player.canUseSkills)
                {
                    //move the cpu towards the ball
                    var smoothStep = MoveToBall(-2);
                    SetMoveAnimation(smoothStep, false);

                    return;
                }
            }

            if (ball.transform.position.x > cpuFieldLimits.x && ball.transform.position.x < cpuFieldLimits.y)
            {
                //move the cpu towards the ball
                var smoothStep = MoveToBall();

                //if cpu is close enough to the ball, make it jump
                var ballDistance = Vector3.Distance(transform.position, ball.transform.position);

                if (ball.transform.position.y > 1f && ballDistance < minJumpDistance && detectGround.IsGrounded() && canJump)
                {
                    canJump = false;
                    anim.SetTrigger("Jump");
                    StartCoroutine(JumpActivation());
                }

                // set move animation
                SetMoveAnimation(smoothStep);
            }
            else
            {
                anim.SetFloat("Speed", 0);
            }

            if (ball.transform.position.x < cpuFieldLimits.x)
            {
                var smoothStep = Mathf.SmoothStep(
                    transform.position.x,
                    maxProtectedDistance,
                    Time.fixedDeltaTime * moveSpeed);

                transform.position = new Vector3(
                    smoothStep,
                    transform.position.y,
                    transform.position.z);
            }
        }
コード例 #2
0
        protected virtual void FixedUpdate()
        {
            if (detectGround.IsGrounded() && inJump)
            {
                inJump = false;

                if (anim != null)
                {
                    anim.SetTrigger("JumpExit");
                }
            }
        }
コード例 #3
0
        protected virtual void OnCollisionEnter(Collision other)
        {
            if (!canUseSkills)
            {
                return;
            }

            if (other.gameObject.tag == "Ball")
            {
                PlaySound();
                Vector3 rebound = new Vector3(Random.Range(0.5f, 1f), Random.Range(-0.5f, -1f), 0);

                // quando a bola só bate no jogador
                if (detectGround.IsGrounded() && axisInput == 0)
                {
                    rebound = new Vector3(Random.Range(0.5f, 1f), Random.Range(0.5f, 1f), 0);
                    // Debug.Log("Kick 1");
                }
                // quando a bola bate no jogador e ele esta pulando
                else if (!detectGround.IsGrounded() && axisInput == 0)
                {
                    rebound = new Vector3(Random.Range(0.5f, 1f), Random.Range(1f, 1.5f), 0);
                    // Debug.Log("Kick 2");
                }
                // quando a bola bate no jogador e ele não esta pulando mas se movendo
                else if (detectGround.IsGrounded() && axisInput != 0)
                {
                    rebound = new Vector3(Random.Range(1f, 1.5f), Random.Range(0.5f, 1f), 0);
                    // Debug.Log("Kick 3");
                }
                // quando a bola bate no jogador e ele esta pulando e se movendo
                else if (!detectGround.IsGrounded() && axisInput != 0)
                {
                    rebound = new Vector3(Random.Range(1f, 1.5f), Random.Range(0.5f, 1f), 0);
                    // Debug.Log("Kick 4");
                }

                if (tag == "Player2")
                {
                    rebound.x = -rebound.x;
                }

                ball.BallRebound(rebound, buttForce);
                IncrementPower(IncrementType.interact);
            }
        }
コード例 #4
0
        protected virtual IEnumerator DisableCollider()
        {
            yield return(new WaitUntil(() => detectGround.IsGrounded()));

            if (!isKnockout)
            {
                yield break;
            }

            rb.isKinematic       = true;
            rb.useGravity        = false;
            thisCollider.enabled = false;

            yield return(new WaitUntil(() => lifeSlider.value > 0));

            rb.isKinematic       = false;
            rb.useGravity        = true;
            thisCollider.enabled = true;
        }