void FixedUpdate()
    {
        //get user input
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        //set forward and right move vectors for the player relative to the camera
        mainCamForward = Vector3.Scale(cam.forward, new Vector3(1.0f, 0.0f, 1.0f)).normalized;
        mainCamRight   = cam.right;

        // calculate move direction to pass to character
        moveInput = v * mainCamForward + h * mainCamRight;

        //copied (from milestone 2) input controls for iso cam control
        if (Input.GetKey(KeyCode.Alpha6))
        {
            isoCam.RotateCamera(0);
        }
        if (Input.GetKey(KeyCode.Alpha7))
        {
            isoCam.RotateCamera(1);
        }
        if (Input.GetKey(KeyCode.Alpha8))
        {
            isoCam.RotateCamera(2);
        }
        if (Input.GetKey(KeyCode.Alpha9))
        {
            isoCam.RotateCamera(3);
        }

        //move the player game object
        Move(moveInput);

        //trying to find ground
        //Raycast worked when finally masking ragdoll and player layers

        /*
         * RaycastHit hit;
         *
         #if UNITY_EDITOR
         * Debug.DrawLine(kayaCollider.bounds.center,new Vector3(kayaCollider.bounds.center.x, kayaCollider.bounds.min.y,kayaCollider.bounds.center.z));
         #endif
         *
         * if (Physics.Raycast (kayaCollider.bounds.center, -Vector3.up, out hit, 100.0f, mask)) {
         *      print ("Found an object - distance: " + hit.distance);
         *      print ("Collider Layer" + LayerMask.LayerToName(hit.transform.gameObject.layer));
         * }*/
        playerGrounded();
    }
    void Update()
    {
        currentBaseState = anim.GetCurrentAnimatorStateInfo(0);          // set  currentState variable to the current state of the Base Layer of animation

        if (!jump)
        {
            jump = Input.GetButtonDown("Jump");

            //play jump effects
            if (jump && currentBaseState.fullPathHash == moveAnimState && !anim.IsInTransition(0))
            {
                Invoke("jumpEffects", 0.1f);
            }
        }

        if (ragDoll)
        {
            Invoke("goForRagdoll", timeToRagdoll);
        }

        if (Input.GetKeyDown(KeyCode.C) | Input.GetButtonDown("Crouch"))
        {
            crouch = !crouch;
        }

        if (Input.GetKeyDown(KeyCode.LeftBracket) | Input.GetButtonDown("RotateViewLeft"))
        {
            camIndex = camIndex - 1;
            if (camIndex < 0)
            {
                camIndex = 3;
            }
        }
        if (Input.GetKeyDown(KeyCode.RightBracket) | Input.GetButtonDown("RotateViewRight"))
        {
            camIndex = camIndex + 1;
            if (camIndex > 3)
            {
                camIndex = 0;
            }
        }
        //update camera view
        isoCam.RotateCamera(camIndex);
    }
Esempio n. 3
0
    private void FixedUpdate()
    {
        isCrouch = Input.GetKey(KeyCode.C);

/*
 *      if (isCrouch) {
 *          if (!crouchToggle) {
 *              animator.SetBool("Crouch", true);
 *              capsule.center = capsule.center / 2;
 *              capsule.height = capsule.height / 2;
 *              isCrouch = false;
 *              crouchToggle = true;
 *          }
 *         else {
 *              animator.SetBool("Crouch", false);
 *              capsule.center = capsuleCenter;
 *              capsule.height = capsuleHeight;
 *              crouchToggle = false;
 *          }
 *      }
 */
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        // calculate move direction to pass to character
        if (cam != null)
        {
            // calculate camera relative direction to move:
            camForward = Vector3.Scale(cam.forward, new Vector3(1, 0, 1)).normalized;
            move       = v * camForward + h * cam.right;
        }
        else
        {
            // we use world-relative directions in the case of no main camera
            move = v * Vector3.forward + h * Vector3.right;
        }

        // walk speed multiplier
        if (Input.GetKey(KeyCode.LeftShift))
        {
            move *= 0.5f;
        }

        if (Input.GetKey(KeyCode.V))
        {
            StartCoroutine(doVault());
        }

        if (Input.GetKey(KeyCode.B))
        {
            StartCoroutine(doSlide());
        }

        if (Input.GetKey(KeyCode.Alpha6))
        {
            isoCam.RotateCamera(0);
        }
        if (Input.GetKey(KeyCode.Alpha7))
        {
            isoCam.RotateCamera(1);
        }
        if (Input.GetKey(KeyCode.Alpha8))
        {
            isoCam.RotateCamera(2);
        }
        if (Input.GetKey(KeyCode.Alpha9))
        {
            isoCam.RotateCamera(3);
        }


        // pass all parameters to the character control script
        Move(move, isJump, isCrouch);
        isJump = false;
    }