コード例 #1
0
        void Update()
        {
            int direction;

            direction = doKeyboardInput();

            wallJumped = true;

            //Reseting speeds if collide with wall
            if (playerPhysics.movementStopped)
            {
                targetSpeed  = 0;
                currentSpeed = 0;

                if (!playerPhysics.grounded)
                {
                    wallJumped = false;
                }
            }


            targetSpeed  = direction * speed;
            currentSpeed = IncrementTowards(currentSpeed, targetSpeed, acceleration);

            //Animation code
            anim.SetFloat("speed", currentSpeed);

            // Check if on ground then jump
            if (playerPhysics.grounded)
            {
                amountToMove.y = 0;
                anim.SetBool("jumping", false);

                // Jump
                if (Input.GetButtonDown("Jump"))
                {
                    amountToMove.y = jumpHeight;
                }
            }
            else if (!playerPhysics.grounded)
            {
                anim.SetBool("jumping", true);
            }

            // Wall jump
            if (!playerPhysics.grounded && playerPhysics.movementStopped && targetSpeed != 0)
            {
                if (Input.GetButtonDown("Jump"))
                {
                    amountToMove.y = jumpHeight;
                    currentSpeed   = IncrementTowards(10 * ((targetSpeed / Mathf.Abs(targetSpeed) * -1)), targetSpeed * -1, 100);
                }
            }

            amountToMove.x  = currentSpeed;
            amountToMove.y -= (gravity * Time.deltaTime);
            playerPhysics.Move(amountToMove * Time.deltaTime);
        }
コード例 #2
0
        void Update()
        {
            wallJumped = true;
            if (keytype == 1)
            {
                direction = key;
            }
            if (keytype == 2)
            {
                if (key > 0)
                {
                    jump = true;
                }
                else
                {
                    jump = false;
                }
            }

            //Updating animation variables
            updateAnimation();

            //Reseting speeds if collide with wall
            if (playerPhysics.movementStopped)
            {
                targetSpeed  = 0;
                currentSpeed = 0;

                if (!playerPhysics.grounded)
                {
                    wallJumped = false;
                }
            }

            targetSpeed  = direction * speed;
            currentSpeed = IncrementTowards(currentSpeed, targetSpeed, acceleration);

            //Animation code
            anim.SetFloat("speed", currentSpeed);

            // Check if on ground then jump
            if (playerPhysics.grounded)
            {
                amountToMove.y = 0;

                // Jump
                if (jump)
                {
                    amountToMove.y = jumpHeight;
                }
            }

            // Wall jump
            if (!playerPhysics.grounded && playerPhysics.movementStopped && targetSpeed != 0)
            {
                if (jump)
                {
                    amountToMove.y = jumpHeight;
                    currentSpeed   = IncrementTowards(10 * ((targetSpeed / Mathf.Abs(targetSpeed) * -1)), targetSpeed * -1, 100);
                }
            }
            jump            = false;
            amountToMove.x  = currentSpeed;
            amountToMove.y -= (gravity * Time.deltaTime);

            playerPhysics.Move(amountToMove * Time.deltaTime);
        }