Exemplo n.º 1
0
    void FixedUpdate()
    {
        RaycastHit hit;

        if (stunnedFor <= 0)
        {
            /**if(Physics.SphereCast(this.transform.position, 1f, Vector3.down, out hit, cc.bounds.extents.x, MovingPlatform))
             * {
             * Vector3 onPlatform = rb.velocity;
             * onPlatform.x = hit.transform.position.x;
             * onPlatform.x += Input.GetAxis(this.tag + "Horizontal") * maxSpeed;
             * if (onPlatform.x >= 0)
             * {
             *   onPlatform.x = Mathf.Min(onPlatform.x, maxSpeed);
             * }
             * else
             *   {
             * onPlatform.x = Mathf.Max(onPlatform.x, maxSpeed * -1);
             *     }
             *     rb.velocity = onPlatform;
             *   }*/
            pushedVelocity.x = 0;
            if (!pd.IsDead())
            {
                Vector3 newX = rb.velocity;



                if ((CompareTag("P1_") || CompareTag("P2_") || CompareTag("P3_") || CompareTag("P4_")))
                {
                    newX.x = Input.GetAxis(this.tag + "Horizontal") * maxSpeed;
                }
                if (newX.x > 0 || newX.x < 0)
                {
                    //newX.x = Mathf.Min(newX.x, maxSpeed);

                    animator.SetTrigger("Walk");
                    if (walkdelay <= 0)
                    {
                        source2 = GetComponent <AudioSource> ();
                        source2.PlayOneShot(singlestep, volume);
                        walkdelay = .3f;
                    }
                    else
                    {
                        walkdelay -= Time.deltaTime;
                    }
                }
                else
                {
                    newX.x = Mathf.Max(newX.x, maxSpeed * -1);
                    animator.SetTrigger("Idle");
                }

                rb.velocity = newX;



                // direction = new Vector3(Input.GetAxis(this.tag + "AimX"), Input.GetAxis(this.tag + "AimY"), 0);
            }


            Vector3 newY = rb.velocity;
            if (Physics.SphereCast(this.transform.position, 1f, Vector3.down, out hit, cc.bounds.extents.x))
            {
                jumpsRemaining = 2;
            }
            else
            {
                if (jumpsRemaining == 2)
                {
                    jumpsRemaining = 1;
                }
                newY.y -= gravity * Time.deltaTime;
            }
            if (((CompareTag("P1_") || CompareTag("P2_") || CompareTag("P3_") || CompareTag("P4_"))) && Input.GetButtonDown(this.tag + "Jump"))
            {
                animator.SetTrigger("Jump");
                source1 = GetComponent <AudioSource>();
                source1.PlayOneShot(doublejump, jumpvol);

                if (jumpsRemaining == 2)
                {
                    newY.y = groundedJumpPower;
                    jumpsRemaining--;
                    jumpBuffer = .2f;
                }
                else if (jumpsRemaining == 1)
                {
                    newY.y = doubleJumpPower;
                    jumpsRemaining--;
                }
            }
            rb.velocity = newY;

            if ((CompareTag("P1_") || CompareTag("P2_") || CompareTag("P3_") || CompareTag("P4_")) && Input.GetButtonDown(this.tag + "Wavedash"))
            {
                Vector3 newDirection = rb.velocity;
                newDirection.x = Input.GetAxis(this.tag + "Horizontal") * maxSpeed;
                newDirection.y = Input.GetAxis(this.tag + "Vertical") * maxSpeed;
            }
        }

        else
        {
            if (hooked)
            {
                if (Mathf.Abs(transform.position.x - hookedDest.x) > .2f)
                {
                    transform.position = Vector3.MoveTowards(transform.position, hookedDest, hookedTime);
                }
                else
                {
                    rb.useGravity = true;
                    hooked        = false;
                    stunnedFor    = .5f;
                }
            }
            else if (pushedVelocity.x != 0)
            {
                rb.velocity = pushedVelocity;
            }

            stunnedFor -= Time.deltaTime;
        }
    }