示例#1
0
    // Update is called once per frame
    void Update()
    {
        var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
        var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;

        transform.Rotate(0, x, 0);
        transform.Translate(0, 0, z);

        if (Input.GetKeyDown(KeyCode.Space) && handOccupied)
        {
            BS.throwBall(transform.forward);
            handOccupied = false;
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        // Ground Check
        onGround = Physics.Raycast(GroundCheck.position, Vector3.down, 0.1f);
        if (handOccupied)
        {
            Debug.Log("hand Occupied");
        }
        else
        {
            Debug.Log("hand Not Occupied");
        }
        // Fire Ball
        if (Input.GetAxis("X " + PlayerNum + " Triggers") < -0.5f && handOccupied)
        {
            ShootDirection = new Vector3(FourthAxis, 0, FifthAxis);
            BS.throwBall(ShootDirection);
            handOccupied = false;
        }

        // Controller Inputs
        xAxis = Input.GetAxis("X " + PlayerNum + " Horizontal");
        yAxis = Input.GetAxis("X " + PlayerNum + " Vertical");
        //Debug.Log("Left Joystick (X: " + xAxis + ", Y: " + yAxis + ")");

        FourthAxis = Input.GetAxis("X " + PlayerNum + " 4th");
        FifthAxis  = Input.GetAxis("X " + PlayerNum + " 5th");
        //Debug.Log("Right Joystick (X: " + FourthAxis + ", Y: " + FifthAxis + ")");
        if (Mathf.Abs(xAxis) < 0.2f)
        {
            xAxis = 0;
        }
        if (Mathf.Abs(yAxis) < 0.2f)
        {
            yAxis = 0;
        }
        if (Mathf.Abs(FourthAxis) < 0.3f)
        {
            FourthAxis = 0;
        }
        if (Mathf.Abs(FifthAxis) < 0.3f)
        {
            FifthAxis = 0;
        }

        // Direction and Movement
        if (xAxis + yAxis + FourthAxis + FifthAxis != 0f)
        {
            direction = new Vector3(xAxis, yAxis).normalized;
            if (direction.magnitude == 0)
            {
                direction = new Vector3(FourthAxis, FifthAxis).normalized;
            }
        }

        if (direction.magnitude != 0 && (xAxis != 0 || yAxis != 0))
        {
            // Direction and Movement
            AngleOfDirection = Mathf.Atan2(direction.y, direction.x) * 180 / (Mathf.PI);
            if (AngleOfDirection < 0.0f)
            {
                AngleOfDirection += 360;
            }
            ROTATION      = Trans.rotation.eulerAngles;
            AngleOfPlayer = 360 - ROTATION.y; // To get the angle to be in the right direction (CCW is POSITIVE)
            //Debug.Log("Y Axis: " + yAxis + ", Angle of Player: " + AngleOfPlayer + ", Angle of Direction: " + AngleOfDirection);
            if (AngleOfDirection < 180 && AngleOfPlayer > 180 & AngleOfDirection + 360 - AngleOfPlayer < 180)
            {
                AngleOfDirection += 360;
            }
            else if (AngleOfPlayer < 180 && AngleOfDirection > 180 & AngleOfPlayer + 360 - AngleOfDirection < 180)
            {
                AngleOfPlayer += 360;
            }
            if ((AngleOfPlayer - AngleOfDirection) > 3.0f)
            {
                Trans.Rotate(0.0f, RotationSpeed * Time.deltaTime, 0.0f);
            }
            else if ((AngleOfPlayer - AngleOfDirection) < -3.0f)
            {
                Trans.Rotate(0.0f, -RotationSpeed * Time.deltaTime, 0.0f);
            }

            // Move Character
            if (!Stunned)
            {
                if (Velocity.x > MaxSpeed)
                {
                    Acceleration.x = -1f;
                }
                else if (Velocity.x == MaxSpeed)
                {
                    Acceleration.x = 0f;
                }
                else
                {
                    Acceleration.x = BoardAcceleration;
                }
            }

            Velocity += Acceleration * Time.deltaTime;
            Trans.Translate(Velocity.x * Time.deltaTime, Velocity.y * Time.deltaTime, Velocity.y * Time.deltaTime);


            MovingFB = true;
        }
        else if (direction.magnitude != 0 && xAxis == 0 && yAxis == 0)
        {
            // Direction and Movement
            AngleOfDirection = Mathf.Atan2(direction.y, direction.x) * 180 / (Mathf.PI);
            if (AngleOfDirection < 0.0f)
            {
                AngleOfDirection += 360;
            }
            ROTATION      = Trans.rotation.eulerAngles;
            AngleOfPlayer = 360 - ROTATION.y; // To get the angle to be in the right direction (CCW is POSITIVE)
            //Debug.Log("Y Axis: " + yAxis + ", Angle of Player: " + AngleOfPlayer + ", Angle of Direction: " + AngleOfDirection);
            if (AngleOfDirection < 180 && AngleOfPlayer > 180 & AngleOfDirection + 360 - AngleOfPlayer < 180)
            {
                AngleOfDirection += 360;
            }
            else if (AngleOfPlayer < 180 && AngleOfDirection > 180 & AngleOfPlayer + 360 - AngleOfDirection < 180)
            {
                AngleOfPlayer += 360;
            }
            if ((AngleOfPlayer - AngleOfDirection) > 3.0f)
            {
                Trans.Rotate(0.0f, RotationSpeed * Time.deltaTime, 0.0f);
            }
            else if ((AngleOfPlayer - AngleOfDirection) < -3.0f)
            {
                Trans.Rotate(0.0f, -RotationSpeed * Time.deltaTime, 0.0f);
            }

            if (!Stunned)
            {
                if (Velocity.x > 0f)
                {
                    Acceleration.x = -4f;
                }
                else if (Velocity.x < 0f)
                {
                    Acceleration.x = 0f;
                }
            }
            Debug.LogWarning("Here");
            Velocity += Acceleration * Time.deltaTime;
            Trans.Translate(Velocity.x * Time.deltaTime, Velocity.y * Time.deltaTime, Velocity.y * Time.deltaTime);

            MovingFB = false;
        }
        else
        {
            if (!Stunned)
            {
                if (Velocity.x > 0f)
                {
                    Acceleration.x = -4f;
                }
                else if (Velocity.x < 0f)
                {
                    Acceleration.x = 0f;
                }
            }
            Debug.LogWarning("Here");
            Velocity += Acceleration * Time.deltaTime;
            Trans.Translate(Velocity.x * Time.deltaTime, Velocity.y * Time.deltaTime, Velocity.y * Time.deltaTime);
            MovingFB = false;
        }

        Debug.LogWarning("Velocity (" + Velocity + ")");
        Debug.LogWarning("Acceleration (" + Acceleration + ")");



        // Jumping
        jumpTime += Time.fixedDeltaTime;
        if (onGround && jumpTime >= 0.3f)
        {
            canJump = true;
            Animate.SetBool("Jumped", false);
            jumpTime = 0;
        }
        if (Input.GetButton("X " + PlayerNum + " A") && onGround && canJump)
        {
            JumpCharacter(jumpForce);
            Animate.SetBool("Jumped", true);
        }
        // onGround
        if (onGround)
        {
            Animate.SetBool("onGround", true);
        }
        else
        {
            Animate.SetBool("onGround", false);
        }

        // Sprint is pressed
        if (Input.GetButton("X " + PlayerNum + " LeftBumper"))
        {
            Sprinting = true;
        }
        else
        {
            Sprinting = false;
        }

        // idle
        if (!MovingFB && !MovingLR && onGround)
        {
            Animate.SetBool("isIdle", true);
            Animate.SetBool("Walking", false);
            Animate.SetBool("Sprint", false);
        }
        else
        {
            Animate.SetBool("isIdle", false);
        }
    }
示例#3
0
    //Inputs
    private void FixedUpdate()
    {
        xAxis      = Input.GetAxis("X " + PlayerNum + " Horizontal");
        yAxis      = Input.GetAxis("X " + PlayerNum + " Vertical");
        FourthAxis = Input.GetAxis("X " + PlayerNum + " 4th");
        FifthAxis  = Input.GetAxis("X " + PlayerNum + " 5th");
        if (Mathf.Abs(xAxis) < 0.2f)
        {
            xAxis = 0;
        }
        if (Mathf.Abs(yAxis) < 0.2f)
        {
            yAxis = 0;
        }
        Debug.Log("4th Axis: " + FourthAxis + "Y Axis: " + FifthAxis);
        onGround = Physics.Raycast(GroundCheck.position, Vector3.down, 0.1f);
        // Rotate
        Trans.Rotate(0, FourthAxis * RotationSpeed * Time.deltaTime, 0);
        FourthAxis = 0;
        FifthAxis  = 0;
        // Forwards and Backwards
        if ((Input.GetKey(Forwards) && !Input.GetKey(Backwards)) || yAxis > 0.0f)
        {
            Animate.SetBool("Forward", true);
            Animate.SetBool("Backward", false);
            MovingFB = true;
            if (!Sprinting)
            {
                Animate.SetBool("Walking", true);
                Animate.SetBool("Sprint", false);
                MoveForwards(yAxis * forwardSpeed, Time.fixedDeltaTime);
            }
            else
            {
                Animate.SetBool("Walking", false);
                Animate.SetBool("Sprint", true);
                MoveForwards(yAxis * forwardSpeed * sprintMultiplier, Time.fixedDeltaTime);
            }
        }
        else if (!Input.GetKey(Forwards) && Input.GetKey(Backwards) || yAxis < 0.0f)
        {
            Animate.SetBool("Forward", false);
            Animate.SetBool("Backward", true);
            MovingFB = true;
            if (!Sprinting)
            {
                Animate.SetBool("Walking", true);
                Animate.SetBool("Sprint", false);
                MoveForwards(yAxis * backwardSpeed, Time.fixedDeltaTime);
            }
            else
            {
                Animate.SetBool("Walking", false);
                Animate.SetBool("Sprint", true);
                MoveForwards(yAxis * backwardSpeed * sprintMultiplier, Time.fixedDeltaTime);
            }
        }
        else
        {
            Animate.SetBool("Forward", false);
            Animate.SetBool("Backward", false);
            MovingFB = false;
        }

        // Left and Right
        if ((Input.GetKey(Right) && !Input.GetKey(Left)) || xAxis > 0.0f)
        {
            Animate.SetBool("StrafeRight", true);
            Animate.SetBool("StrafeLeft", false);
            MovingLR = true;
            if (!Sprinting)
            {
                Animate.SetBool("Walking", true);
                Animate.SetBool("Sprint", false);
                MoveRight(xAxis * sideSpeed, Time.fixedDeltaTime);
            }
            else
            {
                Animate.SetBool("Walking", false);
                Animate.SetBool("Sprint", true);
                MoveRight(xAxis * sideSpeed * sprintMultiplier, Time.fixedDeltaTime);
            }
        }
        else if ((!Input.GetKey(Right) && Input.GetKey(Left)) || xAxis < 0.0f)
        {
            Animate.SetBool("StrafeRight", false);
            Animate.SetBool("StrafeLeft", true);
            MovingLR = true;
            if (!Sprinting)
            {
                Animate.SetBool("Walking", true);
                Animate.SetBool("Sprint", false);
                MoveRight(xAxis * sideSpeed, Time.fixedDeltaTime);
            }
            else
            {
                Animate.SetBool("Walking", false);
                Animate.SetBool("Sprint", true);
                MoveRight(xAxis * sideSpeed * sprintMultiplier, Time.fixedDeltaTime);
            }
        }
        else
        {
            Animate.SetBool("StrafeRight", false);
            Animate.SetBool("StrafeLeft", false);
            MovingLR = false;
        }


        // Jumping
        jumpTime += Time.fixedDeltaTime;
        if (onGround && jumpTime >= 0.3f)
        {
            canJump = true;
            Animate.SetBool("Jumped", false);
            jumpTime = 0;
        }
        if ((Input.GetKeyDown(Jump) || Input.GetButton("X " + PlayerNum + " A")) && onGround && canJump)
        {
            JumpCharacter(jumpForce);
            Animate.SetBool("Jumped", true);
        }
        // onGround
        if (onGround)
        {
            Animate.SetBool("onGround", true);
        }
        else
        {
            Animate.SetBool("onGround", false);
        }

        // Shift is pressed
        if (Input.GetKey(Sprint) || Input.GetButton("X " + PlayerNum + " X"))
        {
            Sprinting = true;
        }
        else
        {
            Sprinting = false;
        }

        // idle
        if (!MovingFB && !MovingLR && onGround)
        {
            Animate.SetBool("isIdle", true);
            Animate.SetBool("Walking", false);
            Animate.SetBool("Sprint", false);
        }
        else
        {
            Animate.SetBool("isIdle", false);
        }

        // Fire Ball
        if ((Input.GetKeyDown(Fire) || Input.GetButton("X " + PlayerNum + " B")) && handOccupied)
        {
            BS.throwBall(Trans.forward);
            handOccupied = false;
        }
    }