Ejemplo n.º 1
0
        // Update is called once per frame



        public void MovePlayer(float playerDirection)
        {
            RaycastHit hit;
            Ray        downRay = new Ray(transform.position, -Vector3.up);

            if (Physics.Raycast(downRay, out hit, 1f))
            {
                if (hit.transform.gameObject.layer == 9)
                {
                    charCont.gameObject.transform.SetParent(hit.transform);
                }
                else
                {
                    charCont.gameObject.transform.SetParent(null);
                }
            }
            else
            {
                charCont.gameObject.transform.SetParent(null);
            }

            if (checkforground)
            {
                grounded = charCont.isGrounded;
            }
            else
            {
                grounded = false;
            }
            playerDir = playerDirection;
            _dash.ManageDashing(grounded, playerDir);

            if (grounded && !waitForJump)
            {
                _jump.resetJumps();
            }

            if (walled != 0)
            {
                _dash.OverrideDash();
            }

            if (!grounded && !checkforwalls)
            {
                //checkforwalls = true;
            }
            if (grounded)
            {
                _wallGrab.notWall = 0f;
                _dash.OverrideDash();
                _dash.ResetDashing();
            }


            if (applyGravity)
            {
                if (grounded)
                {
                    verticleSpeed = -0.1f;
                    checkforwalls = false;
                }
                if (!grounded)
                {
                    if (verticleSpeed > maxVertSpeed)
                    {
                        verticleSpeed -= gravity * Time.deltaTime;
                    }
                }
                if (!waitForJump)
                {
                    checkforwalls = true;
                }
            }

            Upray();
            if (!overrideInput)
            {
                moveVector = new Vector2(playerDirection * speed * speedModifier, verticleSpeed);                 //calculate movement in the x and y
            }

            charCont.Move(moveVector * Time.deltaTime);              //apply movement in the x and y
        }